基于状态变化的可运行角色



我按顺序调用所有角色,现在我必须在运行其他角色之前添加条件检查,

当前main.yml

- hosts: all
gather_facts: no
roles:
- artifacts_copy
- app_build
- db_build
- log_build

artifacts_copy:复制代码

是否可以添加一个条件,如果artifacts_copy角色改变了,那么就运行剩余的角色,否则就跳过剩余的角色

something like this
roles:
- artifacts_copy
when: artifacts_copy.chnaged=true # then run below roles
- app_build
- db_build
- log_build

我刚刚弄明白了,它可能会帮助别人,所以张贴这个答案

角色:

- artifacts_copy
- app_build
- db_build
- log_build

artifacts_copy:/主要任务。Yml添加了set fact

---
# tasks file for artifacts
- name: copy artifacts
copy:
src: files
dest: /root/mycode/
register: artifacts_copy_status
- set_fact:
artifacts_copy_status={{ artifacts_copy_status }}

然后调用下面的role like

---
- hosts: all
gather_facts: no
roles:
- artifacts_copy
- role: app_build
when: artifacts_copy_status.changed | bool ==  true
- role: db_build
when: artifacts_copy_status.changed | bool == true
- role: log_build
when: artifacts_copy_status.changed | bool == true

最新更新