Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
867 views
in Technique[技术] by (71.8m points)

runtimeexception - dict object' has no attribute 'ansible_facts' while checking if a host is reachable in Ansible

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...