Service handlers and error handlers
A task can notify if a change has been made, then a handler can be triggered.
Example:
- name: change_port
- lineinfile: path=/etc/httpd/http.conf regexp=‘^port’ line=‘port=8080’
- notify: Restart_Apache
- handlers:
- name: Restart_Apache
- service: name=apache2 status=restarted
- name: Restart_Apache
Error management of tasks:
- To ignore a change status –> changed_when: false
- For instance uname or service status
- Force a change status if a word is found –> changed_when: “’SUCCESS’ in cmd_output.stdout”
- Force error status if a word is found –>failed_when: “’FAIL’ in cmd_output.stdout”
- Ignore an error status –> ignore_errors: yes
- Easy to test with command –> /bin/false