仅在满足x任务条件的情况下运行yz任务

问题描述 投票:0回答:1

团队,我有10个任务,并且仅在满足task1中的条件时才想运行2-10。

- 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

......

ansible ansible-2.x
1个回答
0
投票

您必须在stat模块调用中使用“路径”,并使用“ block”来组合相关任务,如下所示:

- 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

附加信息:ansible stat moduleblock usage

© www.soinside.com 2019 - 2024. All rights reserved.