ansible.vars.hostvars.HostVarsVars object' has no attribute 'sudo'

Hi,

Could someone help me on subjected issue? I have an playbook which works well when running from command line but the same report an issue running from ansible tower.

FAILED! => {“msg”: “The task includes an option with an undefined variable. The error was: ‘ansible.vars.hostvars.HostVarsVars object’ has no attribute ‘sudo’\n\nThe error appears to be in ‘/tmp/awx_117_n_4nr0rt/project/sudoers.yml’: line 46, column 9, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n post_tasks:\n - name: Sending Mail\n ^ here\n”}

Here is my playbook:

  • name: collect sudousers list
    shell: cat /etc/sudoers|grep -i “ALL=(ALL”|egrep -v “#”|egrep -v “root|wheel”|awk -vq=“” ‘{print (q $0 q)}’ ORS=‘,’
    register: sudo

  • name: Sending Mail
    mail:
    host: test
    port: 25

Hi Kumaresan,

{{ hostvars[host].sudo.stdout }} – Here is the problem. It could not recognize the variable from hostvars[host].sudo.

You did register: sudo but some how the hostsvars[host] is not working in awx. It could be due to the inventory. Have a look again in inventory and also what you have mentioned in hosts: in the playbook.

Thanks & Regards,
Selvam E.