Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ansible Using Custom ssh config File

Tags:

ansible

I have a custom SSH config file that I typically use as follows

ssh -F ~/.ssh/client_1_config amazon-server-01 

Is it possible to assign Ansible to use this config for certain groups? It already has the keys and ports and users all set up. I have this sort of config for multiple clients, and would like to keep the config separate if possible.

like image 434
Luke Exton Avatar asked Feb 17 '15 01:02

Luke Exton


People also ask

Does Ansible use ssh config file?

Ansible will use your SSH config when using the ssh (not paramiko) transport, perhaps it's not finding it for some reason. paramiko would be the default if you were running from RHEL/CentOS 6 or before, where OpenSSH is not new enough to support ControlMaster, and paramiko is therefore still faster.

How do I specify ssh ports in Ansible?

e.g. - name: change ssh ports tasks: - name: edit sshd_config lineinfile .. notify: restart ssh handlers: - name: restart ssh service: sshd state=restarted - name: continue setup vars: - ansible_ssh_port : 5422 tasks: ...


2 Answers

Not fully possible. You can set ssh arguments in the ansible.cfg:

[ssh_connection] ssh_args = -F ~/.ssh/client_1_config amazon-server-01 

Unfortunately it is not possible to define this per group, inventory or anything else specific.

like image 122
udondan Avatar answered Sep 22 '22 11:09

udondan


With Ansible 2, you can set a ProxyCommand in the ansible_ssh_common_args inventory variable. Any arguments specified in this variable are added to the sftp/scp/ssh command line when connecting to the relevant host(s). Consider the following inventory group:

[gatewayed] foo ansible_host=192.0.2.1 bar ansible_host=192.0.2.2 

You can create group_vars/gatewayed.yml with the following contents:

ansible_ssh_common_args: '-o ProxyCommand="ssh -W %h:%p -q [email protected]"' 

and do the trick...

You can find further information in: http://docs.ansible.com/ansible/faq.html

like image 40
Francis Avatar answered Sep 26 '22 11:09

Francis