0

Team, I have 10 tasks and I want to run 2-10 only if condition in task1 is met.

- name: 1Check if the node needs to be processed
  stat: /tmp/fscache-cleaned-up1.log
  register: dc_status
- name: 2Check if the node needs to be processed
  stat: /tmp/fscache-cleaned-up2.log
  register: dc_status
  failed_when: dc_status.stat.exists

.. .. ..

AhmFM
  • 1,552
  • 3
  • 23
  • 53

1 Answers1

1

You have to use "path" in your stat module call and "block" for combining dependant tasks, like this:

- name: Check if the node needs to be processed
  stat:
    path: /tmp/fscache-cleaned-up1.log
  register: dc_status

- name: Run this only when the log file exists
  block:
    - name: Install something
      yum:
        name:
        - somepackage
        state: present

     - name: Apply a config template
      template:
        src: templates/src.j2
        dest: /etc/foo.conf

    - name: Start a service and enable it
      service:
        name: bar
        state: started
        enabled: True
  when: 
    - dc_status.stat.exists
    - dc_status.stat.is_file

Additional information: ansible stat module, block usage

miwa
  • 407
  • 6
  • 13