[英]ansible when condition failing
Can someone help me to understand why this when
condition is failing. when
条件失败时,有人可以帮助我理解为什么会这样。
Below is my Playbook:下面是我的剧本:
- name: restart pkgd once finally for RHEL6 and RHEL7 systems
service:
name: pkgd
enabled: yes
state: restarted
when: ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 7
Error:错误:
TASK [restart pkgd once finally for RHEL6 and RHEL7 systems] ******************************************************************************************************
task path: /home/user/tr_vdi.yml:250
fatal: [myhost]: FAILED! => {}
MSG:
The conditional check 'ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 7' failed. The error was: error while evaluating conditional (ansible_os_family == 'RedHat' and ansible_distribution_major_version|int >= 7): 'ansible_os_family' is undefined
Ansible Ad hoc: Ansible 特设:
devSanbox$ ansible myhost -m setup -a "filter=ansible_distribution_*"
/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py:44: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in a future release.
from cryptography.exceptions import InvalidSignature
myhost | SUCCESS => {
"ansible_facts": {
"ansible_distribution_file_parsed": true,
"ansible_distribution_file_path": "/etc/redhat-release",
"ansible_distribution_file_search_string": "Red Hat",
"ansible_distribution_file_variety": "RedHat",
"ansible_distribution_major_version": "7",
"ansible_distribution_release": "Maipo",
"ansible_distribution_version": "7.8",
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
}
devSanbox$ ansible myhost -m setup -a "filter=ansible_os_family*"
from cryptography.exceptions import InvalidSignature
myhost | SUCCESS => {
"ansible_facts": {
"ansible_os_family": "RedHat",
"discovered_interpreter_python": "/usr/bin/python"
},
"changed": false
ansible version: 2.9 ansible 版本:2.9
I do not see any problem in your play section if you have gather_facts: true
there.如果你有
gather_facts: true
,我在你的游戏部分看不到任何问题。
However, I see many newbie guys overwriting this while disabling it in the ansible.cfg
file.但是,我看到许多新手在
ansible.cfg
文件中禁用它时覆盖了它。
Please check below in your ansible.cfg
file, it should be the reason.请在您的
ansible.cfg
文件中检查以下内容,这应该是原因。
gathering = False
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.