ansible - 仅当在 ansible 中满足 x 任务条件时才运行 yz 任务
问题描述
团队,我有 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
.. .. ..
解决方案
您必须在 stat 模块调用中使用“路径”,并在组合相关任务时使用“块”,如下所示:
- 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 模块,块使用
推荐阅读
- sql - 有没有办法收集在不同的多个 SQL 选择语句运行期间返回的列数据?
- c - 在 C 中添加到链表的开头
- encryption - 如何读取 BEGIN PRIVATE KEY 形式的加密私钥?
- wordpress - 在帐户页面的前端显示用户角色
- arrays - 基于数组创建行
- go - Go 模块管理
- spring-integration - KStream.map 中的空值导致 IllegalArgumentException:有效负载不能为空
- python-3.x - 如何从只有键的列表中生成具有键对值的元组
- groovy - 当 Spock 数据表的标题包含在其他特征方法中命名为变量的变量时的意外行为
- python - Str.split 元素在使用 row 的函数中使用时不存在