Ansible Using Custom ssh config File

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.


I believe you can achieve what you want like this in your inventory:

[group1]
server1

[group2]
server2

[group1:vars]
ansible_ssh_user=vagrant
ansible_ssh_common_args='-F ssh1.cfg'

[group2:vars]
ansible_ssh_user=vagrant
ansible_ssh_common_args='-F ssh2.cfg'

You can then be as creative as you want and construct SSH config files such as this:

$ cat ssh1.cfg
Host server1
     HostName 192.168.1.1
     User someuser
     Port 22
     IdentityFile /path/to/id_rsa

References

  • Working with Inventory
  • OpenSSH Config File Examples

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

Tags:

Ansible