【发布时间】:2021-02-04 17:33:53
【问题描述】:
谁能帮我理解为什么这个when 条件失败了。
下面是我的剧本:
- 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
错误:
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:
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 版本:2.9
【问题讨论】:
-
手动运行
setup模块将为您提供事实。但是你玩gather_facts吗? -
@seshadri_c,是的,我的剧本有
gather_facts: true
标签: ansible ansible-2.x