How do I configure Ansible to use my local SSH config?

I am testing Ansible and am already stuck on a pretty simple thing. I configured /etc/ansible/hosts

mine to host my server's IP:

[web]
1.2.3.4

      

Now connecting to it ansible all -vvvv -m ping

fails because mine ~/.ssh/config

for the specified server uses a custom port, the key file is not in the default location, etc. How do I tell Ansible to reuse my SSH configuration for communication?

+3


source to share


2 answers


It's a bit esoteric, so it's understandable that you missed it. This is on the Ansible Inventory page :

If you have hosts that run on non-standard SSH ports, you can put the port number after the hostname with a colon. The ports listed in your SSH config file will not be used with the paramiko connection, but will be used with the openssh connection.

To make things explicit, it is advised to install them if on default port doesn't work

So in your case:



[web]
1.2.3.4:9000

      

(using 9000

as your alt port of course)

Ansible uses paramiko for ssh version date systems like CentOS / RHEL.

+7


source


What tedder42 said plus some more more advanced ways to figure out your ssh config on a per node basis.

[web]
1.2.3.4 ansible_ssh_port=9000

      

This makes sense if you are also using other ansible_ssh special variables like ansible_ssh_user and ansible_ssh_host.

ansible_ssh_host is useful if you want to be able to refer to a server of your choice instead of its IP.

[web]
apache ansible_ssh_host=1.2.3.4 ansible_ssh_port=9000

      



If you end up with multiple hosts with the same alternate ssh port, you can use the Ansible group variable function.

[web]
1.2.3.4 
5.6.7.8
9.10.11.12

[web:vars]
ansible_ssh_port=9000

      

Ansible will now use port 9000 for all three hosts. In a web group.

Understanding how to organize your inventory data is essential to your success with Ansible.

+3


source







All Articles