Ansible:根据变量值跳过该步骤
如果Ansible变量在变量yml文件中设置为Ansible:根据变量值跳过该步骤,ansible,yaml,ansible-2.x,Ansible,Yaml,Ansible 2.x,如果Ansible变量在变量yml文件中设置为https:off,则应跳过以下代码 默认设置.yml: # Other info ansible_cache_dir: /var/cache/ansible https: off --- - hosts: webclient vars_files: - default_setup.yml - name: Update server.xml tomcat https conf template: src
https:off
,则应跳过以下代码
默认设置.yml
:
# Other info
ansible_cache_dir: /var/cache/ansible
https: off
---
- hosts: webclient
vars_files:
- default_setup.yml
- name: Update server.xml tomcat https conf
template:
src: conf_files/tomcat_server.xml
dest: /opt/tomcat/apache-tomcat-{{ tomcat_ver }}/conf/server.xml
become: true
when: "{{ https }}" == "on"
notify: restart tomcat
provision.yml
:
# Other info
ansible_cache_dir: /var/cache/ansible
https: off
---
- hosts: webclient
vars_files:
- default_setup.yml
- name: Update server.xml tomcat https conf
template:
src: conf_files/tomcat_server.xml
dest: /opt/tomcat/apache-tomcat-{{ tomcat_ver }}/conf/server.xml
become: true
when: "{{ https }}" == "on"
notify: restart tomcat
当我播放这个Ansibleprovision.yml
时,即使我添加了引号(“”),也会出现以下错误
两件事:
- YAML中的
是一个布尔值(同义词off
和false
),因此,如果您保持no
定义不变,就可以使用以下条件:https
when: not https
- 如果您要将https
更改为字符串,即使用:https
那么情况可能是:https: "off"
when: https == "off"