Work_Email
(Work Email)
January 24, 2020, 2:23am
1
Hello Guys,
can someone please explain about “undefined” error
Task
name: reboot if required
win_reboot:
when: update_count.reboot_required
TASK [reboot if required] ********************************************************************************************************************************************************************
task path: /etc/ansible/windows-playbook/copied.yml:22
fatal: [EC2AMAZ-9M186EG.corp.medqia.com ]: FAILED! => {
“msg”: “The conditional check ‘update_count.reboot_required’ failed. The error was: error while evaluating conditional (update_count.reboot_required): ‘update_count’ is undefined\n\n.\n\nThe offending line appears to be:\n\n tasks:\n - name: reboot if required\n ^ here\n”
}
Cheers
At the risk of being rude, I’m not sure what you don’t understand.
You’re querying a hash variable update_count , and looking for the member named reboot_required . Where did you define this variable? If you don’t define a variable, then the variable is undefined.
Is there more to this playbook that you didn’t provide?
Karl_Auer
(Karl Auer)
January 24, 2020, 2:07pm
3
To expand on what Eric said:
Your when: condition refers to a variable called “update_count”.
At the point where you refer to it, that variable does not exist. I bolded the bits of the error message that really matter:
TASK [reboot if required] ********************************************************************************************************************************************************************
task path: /etc/ansible/windows-playbook/copied.yml:22
fatal : [EC2AMAZ-9M186EG.corp.medqia.com ]: FAILED! => {
“msg”: “The conditional check ‘update_count.reboot_required’ failed. The error was: error while evaluating conditional (update_count.reboot_required): ‘update_count’ is undefined \n\n.\n\nThe offending line appears to be:\n\n tasks:\n - name: reboot if required\n ^ here\n”
}
Common reasons for this error include:- you misspelled it
you got the CaPiTaLiSaTiOn wrong
you defined it after first reference
you defined it for a host other than EC2AMAZ-9M186EG.corp.medqia.com
you defined it in a vars file that is not being loaded
you defined it in a vars file that is not being referenced
you defined it somewhere where it cannot be referenced
you rearranged your code and accidentally moved the definition to after the first reference
update_count is a field or element of something bigger you forgot to reference first
you didn’t define it at all
If you’d like more help, post the ENTIRE playbook here (or make it available in e.g. pastebin). Don’t post anything confidential though.
Please post code in a fixed-width font so we can see the indentation.
Regards, K.