Ansible Quirks – 3

I was running some playbook today and realise that the command line arguments of ansible-playbook do not behaves expected.

My playbook has the following defined –

remote_user: root

When I issued the following command, my expectation was that the remote user name would be considered as specified by the “-u” option

$ ansible-playbook -u centos -i '192.168.1.192,' play.yml

However, this does not happen and the playbook still tries to connect as the user defined in the yml file.

So, how do we override what is in the yml file through command line. The only way seems to be possible is using the -e or --extra-vars option as follows –

$ ansible-playbook -e "ansible_ssh_user=centos ansible_ssh_private_key_file=~/.ssh/db_hosts_id_rsa " -i '192.168.1.192,' play.yml

This entry was posted in FLOSS, Tips/Code Snippets and tagged , , . Bookmark the permalink.

Leave a Reply