在我的剧本中我有条件根据playbook命令中的版本执行角色但是当我添加version = 8时它执行两个角色
- hosts: tomcat-servers
remote_user: root
become: yes
become_method: sudo
pre_tasks:
- debug: var=version
roles:
- { role: tomcat7, when: version == '7' }
- { role: tomcat8, when: version == '8' }
命令:
ansible-playbook -i hosts site.yml --extra-vars "version=8"
用于调试输出:
TASK [debug] *******************************************************************
ok: [192.168.139.129] => {
"version": "8"
}
任何帮助?
ansible 2.1.0.0
答案 0 :(得分:2)
(上面的pastebin输出的样本)
ubuntu# ansible-playbook -i hosts site.yml --extra-vars "version=8"
PLAY [tomcat-servers] **********************************************************
TASK [setup] *******************************************************************
ok: [192.168.139.129]
TASK [debug] *******************************************************************
ok: [192.168.139.129] => {
"version": "8"
}
TASK [tomcat7 : Install Java 1.8] **********************************************
skipping: [192.168.139.129]
[..]
TASK [tomcat8 : Install Java 1.8] **********************************************
ok: [192.168.139.129]
TASK [tomcat8 : add group "tomcat"] ********************************************
ok: [192.168.139.129]
[...]
PLAY RECAP *********************************************************************
192.168.139.129 : ok=14 changed=0 unreachable=0 failed=0
从上面的任务可以看出,有两种类型: