3

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?

Billy Billy
  • 423
  • 4
  • 14
  • I am having a similar issue. I've noticed that my ansible 2.10 execution environment works for the template. Still, if I run the same template with the same inventory and use a 2.14 execution environment, I receive the error. – mpmackenna Jun 07 '23 at 19:44

1 Answers1

-1

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!

Jhkcia
  • 305
  • 2
  • 8
  • Putting the password in plaintext seems like a bad solution. Isn't there a way to pull this from e.g. Machine or Network credentials?? – ebarrere Nov 09 '22 at 17:40