刚进入ansible
并想知道您是否可以根据main.yml
中传递的变量在--extra-vars
任务中添加文件?
实施例
main.yml
- 来自角色/任务
# Upload latest json to s3
- include: upload-code.yml
playbook.yml
- 来自剧本
- name: Launch cloudformation stack
hosts: 127.0.0.1
connection: local
roles:
- launch.cloudformation
正如您所看到的,playbook.yml
包含role
而main.yml
包含upload-code.yml
如何根据下面的条件包含upload-code.yml
ansible-playbook playbook.yml --extra-vars "include=upload"
答案 0 :(得分:2)
您可以通过将when
条件应用于包含任务来完成此操作。
- include: upload-code.yml
when:
- include is defined
- include == "upload"
或者,如果您有多个包含文件,也可以使用include
作为名称的一部分。
- include: "{{ include }}-code.yml"
when: include is defined