Failed to connect to host via SSH on Vagrant using Ansible Playbook

I could not find where the real problem is. I executed below playbook with my private key:

--- - hosts: localhost gather_facts: false sudo: yes tasks: - name: Install package libpcre3-dev apt: name=libpcre3-dev state=latest 

But I get the error below on a Vagrant Ubuntu machine:

 PLAY [localhost] ********************************************************************* TASK [Install package ] *************************************************** fatal: [vagrant]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Permission denied (publickey,password).\r\n", "unreachable": true} to retry, use: --limit @/home/vagrant/playbooks/p1.retry PLAY RECAP ********************************************************************* vagrant : ok=0 changed=0 unreachable=1 failed=0 

What could be a possible suggestion?

+6
source share
1 answer

You are using a playbook against localhost with an SSH connection (default in Ansible), and that fails. Most likely, because you never set up an account on your computer to accept the key from yourself. Using the default values, you need to add ~/.ssh/id_rsa.pub to ~/.ssh/authorized_keys .

Instead, to run locally, add connection: local to the game:

 --- - hosts: localhost connection: local tasks: - debug: 

And he will give you the correct answer:

 TASK [debug] ******************************************************************* ok: [localhost] => { "msg": "Hello world!" } 
+5
source

Source: https://habr.com/ru/post/1013596/


All Articles