Play recap and ignored=1 in Ansible

Viewed 133

I am checking whether all services related to a docker-compose.yml are running on a system. The code snippet shown below.

---
  - name: 
    shell: docker-compose ps -q "{{ item }}"
    register: result
    ignore_errors: yes

The code above works as expected. I have to ignore errors otherwise Ansible will not complete. The following result shows ignored=1

PLAY RECAP *******************************************************************************************************
192.168.50.219             : ok=38   changed=12   unreachable=0    failed=0    skipped=0    rescued=0    ignored=1 

If this completes successfully I want to run a subsequent playbook but don't know how to specify ignored=1 correctly.

---
  - name: 
    include_tasks: do_other_things.yml
    when: ignored is false

How do I get the result from PLAY RECAP into something I can test with?

1 Answers

A better idea than trying to cope with the error returned by docker compose ps when the container does not exist would be to use the purposed module: docker_container_info to achieve the same.

Given the playbook:

- hosts: localhost
  gather_facts: no

  tasks:
    - docker_container_info:
        name: "{{ item }}"
      register: containers
      loop: 
        - node1     # exists
        - node404   # does not exists

    - debug:
        msg: "`{{ item.item }}` is not started" 
      loop: "{{ containers.results }}"
      loop_control:
        label: "{{ item.item }}"
      when: not item.exists

This would yield:

TASK [docker_container_info] *************************************************
ok: [localhost] => (item=node1)
ok: [localhost] => (item=node404)

TASK [debug] *****************************************************************
skipping: [localhost] => (item=node1) 
ok: [localhost] => (item=node404) => 
  msg: `node404` is not started
Related