Hi,
I need to add ssh-agent for root user. so I use below command through ansible task but getting an error.
eval ssh-agent -s
&& ssh-add ~/.ssh/id_rsa"
please give me task to perform below command on my target machine.
Hi,
I need to add ssh-agent for root user. so I use below command through ansible task but getting an error.
eval ssh-agent -s
&& ssh-add ~/.ssh/id_rsa"
please give me task to perform below command on my target machine.
what error are you getting ?
Hi Jonathan,
actually i m not getting error when i run playbook but after i will login to client machine and check using “ssh-add -l” command then i get “Could not open a connection to your authentication agent” error.
Can you send me task code to perform this operation.
try
ssh-agent bash
then
ssh-add
Hi Jonathan,
But which module I use to run eval ssh-agent -s
or ssh-add /root/bashrc.
Shell/command/action/raw module to create task for above command
what exactly are you trying to accomplish?
Hi Jonathan,
I use below task in my playbook,
ssh-agent -s
&& ssh-add ~/.ssh/id_rsa”When i run playbook no error found,
But I log in to my client machine and type “ssh-add -l” command then I get below error
The “ssh-agent” and “ssh-add” are usually run on a system as a specific user to add an SSH key to a temporary ‘keychain’ so any subsequent SSH commands can automatically (and without prompting) use a specific ssh key to connect to a second system.
When you run them in the Ansible “shell” module, it’s running those on the remote system and once that module completes, the ssh keychain process (“ssh-agent”) is closed and it goes away.
As Johnathan asked, what are you trying to get setup by running these steps? It looks like you’re trying to get it setup so you can SSH into the “ubuntu-target” system as root using the “id_rsa” key on “ubuntu” . (But since your ansible-playbook command doesn’t prompt for credentials, it appears you already have the shared ssh key setup, so I’m confused what larger problem you’re trying to solve…)
Hi Dan,
Thanks for providing information.
Actually, I have already add key file to client machine.
I have a question …The task i wrote in playbook in correct or not ? if it wrong can you send me the correct task to perform those command on client machine.
shell: “eval ssh-agent -s
&& ssh-add ~/.ssh/id_rsa”
Hi Pranay,
You asked, is “task i wrote in playbook in correct or not ?”
Based on the output from your playbook provided earlier, the tasks/commands (“ssh-agent” and “ssh-add”) ARE being executed on the remote machine without error - the yellow “changed:” response notes that the “shell:” module ran and the two commands did not return an error.
Back to the question we asked earlier, what are you trying to get setup by running these steps?
Until you can tell us what you’re trying to do exactly by running these commands, we can’t really help you further. You’ve setup the “shell:” module properly and the commands run without error. Until we know what you’re trying to do later we can’t provide any further assistance.
Hi Dan,
Actually we install some of my on-premises software on remote machine but we required ssh-agent configured on that remote machine to install this software.
without authenticate with that keys we can not able to install this software on my remote machine.
is their any way to check the below task was running properly on my remote machine.
shell: “eval ssh-agent -s
&& ssh-add ~/.ssh/id_rsa”
If the ssh-agent must be running for your installer to complete, then you’ll probably have to run it after the ssh-add:
shell: “eval ssh-agent -s
&& ssh-add ~/.ssh/id_rsa && /path/to/installer”
My gut feeling is that there’s something missing that would make your task a lot easier and not need the ssh-agent/ssh-add processes.