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]