playbook.yml пытаемся установить не существующий пакет treeee и выводим echo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
--- - name: Error find and control hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present - name: Tasks number2 shell: echo Hellow world! - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml ignore_errors игнорим ошибки и выполняем следующие таски
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
--- - name: Error find and control hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: echo Hellow world! - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml дебаг ignore_errors
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
--- - name: Error find and control hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: ls -la /var/ register: results - debug: var: results - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml failed_when
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
--- - name: Test ansible hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: echo Hellow world register: results failed_when: "'world' in results.stdout" - debug: var: results - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml failed_when result.rc
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
--- - name: Test ansible hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: echo Hellow world register: results failed_when: result.rc == 0 # failed_when: "'world' in results.stdout" - debug: var: results - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml выполнится только там где есть file1.txt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
--- - name: Test ansible hosts: all become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: cat /home/secret/file1.txt register: results - debug: var: results - name: Tasks number3 shell: echo Privet Man! ... |
playbook.yml any_errors_fatal
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
--- - name: Test ansible hosts: all any_errors_fatal : true become: yes tasks: - name: Tasks number1 yum: name=treeee state=present ignore_errors: yes - name: Tasks number2 shell: cat /home/secret/file71.txt register: results - debug: var: results - name: Tasks number3 shell: echo Privet Man! ... |