I have the below playbook code as suggested in order to check if the inventory hosts are reachable.
---
- hosts: "{{ENV}}_*"
user: "{{USER}}"
tasks:
- fail:
msg: "Server is UNREACHABLE."
when: hostvars[item].ansible_facts|list|length == 0
with_items: "{{ ansible_play_hosts }}"
I get the below error running the playbook:
TASK [] ****************************************
fatal: [remotehost.com]: FAILED! => {"msg": "The conditional check 'hostvars[item].ansible_facts|list|length == 0' failed. The error was: error while evaluating conditional (hostvars[item].ansible_facts|list|length == 0): 'dict object' has no attribute 'ansible_facts'
The error appears to have been in '/web/aes/admin/playbooks/restart.yml': line 9, column 10, but may
be elsewhere in the file depending on the exact syntax problem.
The offending line appears to be:
- fail
^ here
"}
Need suggestions on how to I fix this error ?
question from:
https://stackoverflow.com/questions/65944614/dict-object-has-no-attribute-ansible-facts-while-checking-if-a-host-is-reacha 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…