Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I override Ansible SSH key inventory variable ansible_ssh_private_key_file on command line?

In Ansible 2.4.2.0, can I override the SSH key set in inventory with ansible_ssh_private_key_file on command line? It is not possible with --private-key option as reported on this issue: Command-line flags (variable weight) not respected (bug or a feature?)

The inventory file:

[group1]
instance1   ansible_host=host1  ansible_user=user1  ansible_ssh_private_key_file=~/.ssh/user1host1-id_rsa

Command line:

ansible-playbook playbook1.yml --private-key=some_other-id_rsa
like image 452
apa64 Avatar asked May 25 '18 09:05

apa64


People also ask

How do I change my Ansible inventory path?

Ansible works against multiple systems in your infrastructure at the same time. It does this by selecting portions of systems listed in Ansible's inventory file, which defaults to being saved in the location /etc/ansible/hosts . You can specify a different inventory file using the -i <path> option on the command line.

What are the different ways other than SSH by which Ansible can connect to remote hosts?

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.

Which is the default Ansible inventory file?

The default location for the inventory file is /etc/ansible/hosts. You can also create project-specific inventory files in alternate locations. The inventory file can list individual hosts or user-defined groups of hosts.


1 Answers

You can override any variable using --extra-vars parameter which takes the priority over variables defined in any other place:

ansible-playbook playbook1.yml --extra-vars="ansible_ssh_private_key_file=some_other-id_rsa"
like image 56
techraf Avatar answered Nov 15 '22 09:11

techraf