我有以下几点,其中包括一位同事在老角色中的内容。
---
- name: deploy
include: deploy.yml
when: deploy is defined and deploy == 'True'
- name: undeploy
include: undeploy.yml
when: undeploy is defined and undeploy == 'True'
- name: database-migrate
include: database-migrate.yml
when: db is defined and db == 'True'但是,不管我如何包含角色,Ansible都会自动处理每个包含。我可以使用-列表任务选项来验证这一点。
例如,在我的剧本中,我有以下内容
roles:
- { role: vip-notification-services-app, deploy: 'True', tags: ['deploy']}我使用2.1.1.0版本运行(几周前升级)。此角色在升级之前执行良好。
因此,我想知道这种类型的includes在角色中是否不再被允许,或者我需要使用一些不同的语法。
发布于 2016-10-09 01:42:48
--list-tasks选项它不为其结果计算when条件。
也就是说,如果你有一个playbook.yml
---
- hosts: localhost
connection: local
tasks:
- debug:
when: falseansible-playbook playbook.yml --list-tasks将显示:
playbook: test.yml
play #1 (localhost): localhost TAGS: []
tasks:
debug TAGS: []尽管debug任务永远不会运行(如果将条件更改为with: true,则结果不会改变)。
作为Konstantin Suvorov noticed,include总是包含所有任务,然后对每个任务应用when条件。因此,在--list-tasks结果中,您将始终看到所有任务。然而,它们不会在真正的运行中被执行。
https://stackoverflow.com/questions/39922078
复制相似问题