I want to use a public aws keypair .pem file for running ansible playbooks. I want to do this without changing my ~/.ssh/id_rsa.pub
and I can't create a new keypair from my current ~/.ssh/id_rsa.pub
and apply it to the ec2 instances I am trying to change.
$ ansible --version ansible 1.9.6 configured module search path = None
Here is my hosts file (note that my actual ip is replaced with 1.2.3.4
). This is probably the issue since I need a way to set a public key variable and use that:
[all_servers:vars] ansible_ssh_private_key_file = ./mykeypair.pem [dashboard] 1.2.3.4 dashboard_domain=my.domain.info
Here is my playbook:
--- - hosts: dashboard gather_facts: False remote_user: ubuntu tasks: - name: ping ping:
This is the command I am using to run it:
ansible-playbook -i ./hosts test.yml
It results in the following error:
fatal: [1.2.3.4] => SSH Error: Permission denied (publickey). while connecting to 1.2.3.4:22
There is no problem with my keypair:
$ ssh -i mykeypair.pem [email protected] 'whoami' ubuntu
What am I doing wrong?
Setting up SSH keys By default, Ansible assumes you are using SSH keys to connect to remote machines. SSH keys are encouraged, but you can use password authentication if needed with the --ask-pass option. If you need to provide a password for privilege escalation (sudo, pbrun, and so on), use --ask-become-pass .
Ok little mistakes I guess you can't have spaces in host file variables and need to define the group you are applying the vars to. This hosts file works with it all:
[dashboard:vars] ansible_ssh_private_key_file=./mykeypair.pem [dashboard] 1.2.3.4 dashboard_domain=my.domain.info
I have come across this and all what I had to do was to run the below
#ssh-agent bash #ssh-add ~/.ssh/keypair.pem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With