Collecting error messages generated during fact gathering

Hi,

# hosts
[all]
localhost ansible_connection=local
8.8.8.8


# test.yml
---
- hosts: all
  gather_facts: false
  tasks:
    - name: Gather
      ansible.builtin.setup:
      ignore_errors: true
      ignore_unreachable: true
      register: _g

    - name: Debug failed
      ansible.builtin.debug:
        var: _g
      when: (ansible_facts | length) == 0

Running ansible-playbook -i hosts test.yml yields:

PLAY [all] ***********************************************************************************************************

TASK [Gather] ********************************************************************************************************
ok: [localhost]
[ERROR]: Task failed: Failed to connect to the host via ssh: ssh: connect to host 8.8.8.8 port 22: Connection timed out
Origin: /home/mikemorency/test2.yml:5:7

3   gather_facts: false
4   tasks:
5     - name: Gather
        ^ column 7

fatal: [8.8.8.8]: UNREACHABLE! => {"changed": false, "msg": "Task failed: Failed to connect to the host via ssh: ssh: connect to host 8.8.8.8 port 22: Connection timed out", "unreachable": true}
...ignoring

TASK [Debug failed] **************************************************************************************************
skipping: [localhost]
ok: [8.8.8.8] => {
    "_g": {
        "changed": false,
        "exception": "(traceback unavailable)",
        "msg": "Task failed: Failed to connect to the host via ssh: ssh: connect to host 8.8.8.8 port 22: Connection timed out",
        "unreachable": true
    }
}

PLAY RECAP ***********************************************************************************************************
8.8.8.8                    : ok=2    changed=0    unreachable=0    failed=0    skipped=0    rescued=0    ignored=1   
localhost                  : ok=1    changed=0    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0   

I hope this helps

1 Like