Define ssh key per host using ansible_ssh_private_key_file

www.lau‮utt‬ri.com
Define ssh key per host using ansible_ssh_private_key_file

In Ansible, the ansible_ssh_private_key_file variable allows you to specify a different private SSH key file for each host in your inventory. This can be useful if you have multiple servers that require different SSH keys for authentication.

To define the ansible_ssh_private_key_file variable for a specific host, you can use the vars section in your playbook or inventory file. For example, to specify a different private key file for host server1, you could use the following syntax:

[all:vars]
ansible_ssh_private_key_file = /path/to/default/key

[server1]
ansible_ssh_private_key_file = /path/to/server1/key

In this example, the default private key file is set in the vars section and then overridden for the server1 host. You can specify a different private key file for any number of hosts in this way.

It's also possible to specify the ansible_ssh_private_key_file variable as a host variable in your inventory file. For example:

[server1]
host1 ansible_ssh_private_key_file=/path/to/server1/key

This allows you to set the private key file for a specific host in the inventory file, rather than in the playbook.

It's important to note that the ansible_ssh_private_key_file variable should be the path to the private key file on the Ansible control machine, not on the target host.

Created Time:2017-10-28 14:02:27  Author:lautturi