La variable error_code a continuación contiene esta cadena:
"fallido": verdadero
¿Cómo puedo usar esta cadena como disparador para el módulo 'cuando? No estoy seguro de cómo escapar de estos caracteres especiales, por lo que el libro de jugadas los interpreta correctamente. Esto es lo que he intentado pero no funciona:
- name: copying index copy: src: /tmp/index.html dest: /var/www/html/ notify: reloadone register: error_code - name: verify content fail: msg: There has been an error with the index file when: " \"failed\"\: true in error_code" handlers: - name: reloadone systemd: state: restarted name: httpdPonga la cadena en las comillas simples , por ejemplo
- hosts: localhost gather_facts: false vars: error_code: '"failed": true' tasks: - debug: var: error_code - name: verify content fail: msg: There has been an error with the index file when: error_code == result vars: result: '"failed": true'da
TASK [debug] ****************************************************** ok: [localhost] => error_code: '"failed": true' TASK [verify content] ********************************************* fatal: [localhost]: FAILED! => changed=false msg: There has been an error with the index fileLa siguiente opción es convertir la cadena en un diccionario y probar el valor booleano del atributo fallido , por ejemplo
- hosts: localhost gather_facts: false vars: error_code: '"failed": true' tasks: - debug: var: error_code|from_yaml - name: verify content fail: msg: There has been an error with the index file when: result.failed vars: result: "{{ error_code|from_yaml }}"da
TASK [debug] **************************************************** ok: [localhost] => error_code|from_yaml: failed: true TASK [verify content] ******************************************* fatal: [localhost]: FAILED! => changed=false msg: There has been an error with the index fileSi el código no falla
error_code: '"failed": false'la condición será saltada
TASK [debug] ***************************************************** ok: [localhost] => error_code|from_yaml: failed: false TASK [verify content] ******************************************** skipping: [localhost]