Article 5MCA0 ansible when/include "ansible_distribution' is undefined" problem

ansible when/include "ansible_distribution' is undefined" problem

by
PoleStar
from LinuxQuestions.org on (#5MCA0)
Hello,

It will make things much simpler if I can include playbook(.yml) if the condition is met... but ansible does not read variable in main.yml

Code:]$ cat main.yml

- include: yum7_orch.yml
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"
Code:a
]$ ansible-playbook --check -i DELETE playbooks-dev/yum.setup/main.yml | tee

[DEPRECATION WARNING]: 'include' for playbook includes. You should use 'import_playbook' instead. This feature will be removed in version 2.12. Deprecation warnings can be disabled by setting deprecation_warnings=False in ansible.cfg.

PLAY [Print linux distribution and version] **********************************************************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************************************************************************************************************
fatal: [10.xx.xx.xxx]: FAILED! => {"msg": "The conditional check 'ansible_distribution == \"CentOS\" and ansible_distribution_major_version == \"7\"' failed. The error was: error while evaluating conditional (ansible_distribution == \"CentOS\" and ansible_distribution_major_version == \"7\"): 'ansible_distribution' is undefined"}

PLAY RECAP *******************************************************************************************************************************************************************************************************************************************************************************************************************************
10.xx.xx.xxx : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0BTW same condition check from yum7_orch.yml
Code:
]$ grep when yum7_orch.yml
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"Thank you.latest?d=yIl2AUoC8zA latest?i=J2ataHIGJtE:rlxvDBiaEV8:F7zBnMy latest?i=J2ataHIGJtE:rlxvDBiaEV8:V_sGLiP latest?d=qj6IDK7rITs latest?i=J2ataHIGJtE:rlxvDBiaEV8:gIN9vFwJ2ataHIGJtE
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments