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

1

9

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
Extenuate answered 25/5, 2018 at 9:54 Comment(1)
There's an answer in the thread you linked to.Lashaunda
L
8

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"
Lashaunda answered 25/5, 2018 at 9:58 Comment(1)
Oh, of course, I saw the discussion about -e on the issue tracker page but didn't realize that ansible_ssh_private_key_file in hosts.ini is just a variable after all! Thank you!Extenuate

© 2022 - 2024 — McMap. All rights reserved.