User Tools

Site Tools


ansible_unresponsive_hosts

So using Tower, you'll want to sometimes ignore offline hosts, but don't want the playbook to error. I've tried ignore_unresponsive, but it ignores the servers for the follow tasks in the play, but will still error when run in Tower (as of 3.6.3, and Ansible 2.9)

I found this and it works out (from here https://stackoverflow.com/questions/55188936/ansible-how-to-ignore-unreachable-hosts-before-ansible-2-7-x

---
- hosts: all
  connection: local
  gather_facts: no
  tasks:
    - block:
        - name: determine hosts that are up
          wait_for_connection:
            timeout: 5
          vars:
            ansible_connection: ssh
        - name: add devices with connectivity to the "running_hosts" group
          group_by:
            key: "running_hosts"
      rescue:
        - debug: msg="cannot connect to {{inventory_hostname}}"

- hosts: running_hosts

After the second hosts:, you still put in all you standars (like gather_facts, or serial). It works by adding the hosts to a new group, and then running the remaining tasks against that group.

ansible_unresponsive_hosts.txt · Last modified: 2020/05/22 17:33 by The SuperUser