[英]Ansible set environment variable from a file and access it within the playbook
[英]How to set an Ansible tag from within a playbook?
我想基于条件值跳过一些戏剧。 我可以在开始时执行一项任务,在满足条件时跳过其他一些任务。
我知道我总是可以使用set_fact
并将其作为运行其他游戏(角色和任务)的条件,或者在我想跳过的每个游戏中直接评估所述条件。
但是,由于游戏已经有了标记系统,在set_tags
中有类似set_tags
的东西,我可以利用它来避免在我的游戏中添加条件并膨胀我已经很重的剧本。
像这样的东西:
- name: skip terraform tasks if no file is provided
hosts: localhost
tasks:
set_tags:
- name: terraform
state: skip
when: terraform_files == ""
我想跳过的两部戏剧:
- name: bootstrap a testing infrastructure
hosts: localhost
roles:
- role: terraform
state: present
tags:
- create_servers
- terraform
[...]
- name: flush the testing infrastructure
hosts: localhost
roles:
- role: terraform
state: absent
tags:
- destroy_servers
- terraform
如果我理解正确,应该做以下事情。
- name: bootstrap a testing infrastructure
hosts: localhost
roles:
- role: terraform
state: present
when: terraform_files != ""
tags:
- create_servers
- terraform
[...]
- name: flush the testing infrastructure
hosts: localhost
roles:
- role: terraform
state: absent
when: terraform_files != ""
tags:
- destroy_servers
- terraform
这与在角色中的每个任务上设置when子句基本相同。 因此,如果条件为假,将检查每个任务但跳过。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.