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
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.
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.
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.
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"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With