handlers练习

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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章