2017-02-16 3 views
0

Der folgende Code sollte überspringen, wenn die Ansible-Variable auf https: off in Variablen YML-Datei gesetzt ist.Ansible: Überspringt den Schritt basierend auf einem Variablenwert

default_setup.yml:

# Other info 
ansible_cache_dir: /var/cache/ansible 
https: off 

provision.yml:

--- 
- 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 

Wenn ich spiele diese ansible provision.yml die folgende Fehlermeldung erhalten, obwohl ich das Zitat ("") hinzugefügt

ERROR! Syntax Error while loading YAML. 


    The error appears to have been in '/home/centos/check-tomcat/roles/nginx/tasks/main.yml': line 24, column 23, but maybe elsewhere in the file depending on the exact syntax problem. 

The offending line appears to be: 

    become: true 
    when: "{{ https }}" == "on" 
       ^here 
We could be wrong, but this one looks like it might be an issue with 
missing quotes. Always quote template expression brackets when they 
start a value. For instance: 

     with_items: 
     - {{ foo }} 

    Should be written as: 

     with_items: 
     - "{{ foo }}" 

Antwort

1

Zwei Dinge:

  • off in YAML ist ein boolescher Wert (Synonym für false und no), wenn Sie also die https Definition lassen, wie ist, dann ist es genug, um die folgende Bedingung zu verwenden:

    when: not https 
    
  • , wenn Sie ‚d https in eine Zeichenfolge ändern, dh mit:

    https: "off" 
    

    dann könnte die Bedingung sein:

    when: https == "off" 
    
Verwandte Themen