Tuesday, March 16, 2021

Ansible - Generating ssh key with passphrage and executing the commands

 New security rule is implemented to add passcode to your ssh private key.
This messed up running ansible jobs.

You have to generate new key, update to your all systems.

Verify if ssh-key has password set up or not
$ ssh-keygen -y -f ~jay/.ssh/id-rsa-pub
if it does not prompt you for password, you have to re-create the key.

to create the key with password run the following command
$ ssh-keygen -n [passphrase]

now, you have to update your key to all servers.
If you have your home dire shared, you are good. This is the case at my env.


Once you copy your keys, now, time to run ansible commands, it will fail until you supply your passphrase.

There might be many different ways to do this but I used ssh-agent

$ eval $(ssh-agent)
$ ssh-add ~jay/id-rsa
you enter the passphrase
it will be in memory so you can run all ansible commands without supplying the passphrase.

$ cat my_hosts
lsdv.eg.com
lsdk.eg.com
lsdm.eg.com
lsdn.eg.com

$ ansible -i my_hosts all -m yum -a "state=present name=/repo/apps/code/code.12.2-234.el7.x86_64.rpm" -b -K
$ ansible -i my_hosts all -a "rpm -qa code" -b -K
$ ansible -i my_hosts all -a "aide --init" -b -K
$ ansible -i my_hosts all -a "cp -a /var/tmp/resolv.conf /etc/resolv.conf" -b -K
$ ansible -i my_hosts all -a "ls -lh /etc/resolv.conf" -b -K


No comments:

Post a Comment

Git branch show detached HEAD

  Git branch show detached HEAD 1. List your branch $ git branch * (HEAD detached at f219e03)   00 2. Run re-set hard $ git reset --hard 3. ...