Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible SSH ERROR connection in localhost

I have this error when I launch my playbook against the localhost host.

TASK [setup] ******************************************************************* fatal: [127.0.0.1]: UNREACHABLE! => {"changed": false, "msg": "SSH encountered an unknown error during the connection. We recommend you re-run the command using -vvvv, which will enable SSH debugging output to help diagnose the issue", "unreachable": true} to retry, use: --limit @deploy-test-env.retry  PLAY RECAP ********************************************************************* 127.0.0.1                  : ok=0    changed=0    unreachable=1    failed=0 

And my hosts file have this config:

[local] 127.0.0.1 

What is the problem?

Thanks!

like image 474
Miguel Avatar asked May 12 '16 10:05

Miguel


People also ask

Can I use Ansible without SSH?

Ansible can use a variety of connection methods beyond SSH. You can select any connection plugin, including managing things locally and managing chroot, lxc, and jail containers.

How do I specify SSH ports in Ansible?

One of the first things I do when I get my hands on a new linux server is to change the SSH port. It's a basic, easy and efficient way of warding most brute force attempts. In a nutshell, you edit the Port parameter of /etc/ssh/sshd_config , restart sshd and you're done.


2 Answers

Ansible by default tries to connect through ssh. For localhost you should set the connection to local.

You can define this when calling the playbook:

ansible-playbook playbook.yml --connection=local 

Define it in your playbook:

- hosts: local   connection: local 

Or, preferable, define it as a host var just for localhost/127.0.0.1. Create a file host_vars/127.0.0.1 relative to your playbook with this content:

ansible_connection: local 

You also could add it as a group var in your inventory:

[local] 127.0.0.1  [local:vars] ansible_connection=local 

or as a host var:

[local] 127.0.0.1   ansible_connection=local 

See Behavioral Parameters in docs.

like image 94
udondan Avatar answered Oct 01 '22 01:10

udondan


It could be done way more easier.

Under the [defaults] section of the ansible.cfg file, just paste the following line:

transport = local 
like image 35
Гдето Якутский Avatar answered Sep 30 '22 23:09

Гдето Якутский