Ansible:根据变量值跳过该步骤

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

如果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: 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
当我播放这个Ansible
provision.yml
时,即使我添加了引号(“”),也会出现以下错误

两件事:

  • YAML中的
    off
    是一个布尔值(同义词
    false
    no
    ),因此,如果您保持
    https
    定义不变,就可以使用以下条件:

    when: not https
    
  • 如果您要将https
    https
    更改为字符串,即使用:

    https: "off"
    
    那么情况可能是:

    when: https == "off"