3.1 問題
本案例要求:
安裝Apache軟件
配置文件,重新載入配置文件讓服務生效
使用handlers來實現
3.2 步驟
實現此案例需要按照如下步驟進行。
步驟一:error
playbook從上往下順序執行,若報錯,後面的命令不會在執行,若想解決可以使用ignoring_errors:True(使用這個,會有報錯信息,告訴你錯誤忽略,繼續執行下面的命令)
[root@ansible ansible]# vim error.yml
- hosts: web
remote_user: root
tasks:- shell: mkdir /tmp/cache
- name: ReStart service httpd
service:
name: httpd
state: restarted - name: run some command
shell: /usr/bin/somecommand
ignore_errors: True
[root@ansible ansible]# ansible-playbook error.yml
PLAY [web] ***********************************************************************************
TASK [Gathering Facts] ***********************************************************************************
ok: [web2]
ok: [web1]
TASK [command] ***********************************************************************************
[WARNING]