Ansible ansible_password undefined variable

Viewed 3102

This is driving me crazy. My playbook looks as follows:

---                                                                                                                                                                                                         
- hosts: all
  become_user: root
  become_method: sudo
  become: yes
  vars:
     ansible_become_password: "{{ ansible_password }}"

ansible_password is a variable that is supposed to be populated by Ansible Tower / AWX. But I am getting below error message:

fatal: [RHEL8]: FAILED! => {"msg": "The field 'become_pass' has an invalid
value, which includes an undefined variable. The error was: 'ansible_password' is undefined"}

It tells me that ansible_password is undefined. But if I a hardcode the password there and log ansible_password at the end of the playbook execution, i see that ansible_password is well defined. So, it seems like ansible_password is only defined in the scope of tasks.

Anybody has experience with this? What would be the way around this issue?

1 Answers

This error occurs if you don't provide ansible_password variable,

if you run ansible using ansible-playbook command pass ansible_password as argument to your command :

ansible-playbook test.yml -i host.ini -e "ansible_password=YourPassword"

or add it to your host.ini file like:

[all]
0.0.0.0

[all:vars] 
ansible_password=YourPassword

or if you use AWX, add this variable to your extra variables: awx extra variable setting

That should work.

Good luck!

Related