个人记录,playbook的一些用法

之前预想通过ansible, celery 来实现一键重启cognos,包括重启apache2,dispatch,content store,并在每个组建关闭或启动完成后的检查,通过检查后在关闭或启动下一个组建,大概的demo实现了,只是遗憾没有时间正真的配合cognos环境运用起来,先大概的记录一下吧

stopapache2.yml

---
- hosts: "stopapache2"
  gather_facts: false
  tasks:
    - name: "stop apache2"
      shell: sh /home/wfq/asb/stopapache2.sh
      register: stop_result
    - name: "check stdout"
      shell: echo cc `date + '%Y%m%d %H:%M:%S'` {{ stop_result.stdout }}, for check >> /home/wfq/asb/asb.log
    - name: "inform users"
      shell: echo cc `date + '%Y%m%d %H:%M:%S'` {{ stop_result.stdout }} stopapache2 succes, inform users by mail >> /home/wfq/asb/asb.log
      when: "'stop apache2 success' in stop_result.stdout"

stopapp.yml

---
- hosts: "mis1c10_app"
  gather_facts: false
  tasks:
    - name: "stop_mis1c10_app"
      shell: sh /home/wfq/asb/stop_mis1c10_app.sh
      register: stop_result
    - name: "check stdout"
      shell: echo {{ stop_result.stdout }}, for check >> /home/wfq/asb/asb.log
    - name: "inform users"
      shell: echo {{ start_result.stdout }} stop app success, inform users by mail >> /home/wfq/asb/asb.log
      when: "'stop mis1c10 app success' in stop_result.stdout"

stopcm.yml

---
- hosts: "mis1c10_cm"
  gather_facts: false
  tasks:
    - name: "stop_mis1c10_cm"
      shell: sh /home/wfq/asb/stop_mis1c10_cm.sh
      register: stop_result
    - name: "check stdout"
      shell: echo {{ stop_result.stdout }}, for check >> /home/wfq/asb/asb.log
    - name: "inform users"
      shell: echo {{ start_result.stdout }} stop cm success, inform users by mail >> /home/wfq/asb/asb.log
      when: "'stop mis1c10 cm success' in stop_result.stdout"

猜你喜欢

转载自blog.csdn.net/wang725/article/details/80329752
今日推荐