ansible 添加 cron 任务

  1. 找到相应的role, 假设以storm_nimbus为例,将要完成的任务脚本放在files目录下。
    例如:

    vim roles/storm_nimbus/files/storm-recovery

    
    #!/bin/bash
    
    
    service=storm-mesos
    
    if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 3 )); then
        echo "`date`: $service are running!!!"
    else
        echo "`date`: $service are starting..."
        systemctl start storm-mesos-nimbus
        systemctl start storm-ui
        systemctl start storm-drpc
        #上面三条也可以合成一条:
        #systemctl start storm-{mesos-nimbus,ui,drpc}
        echo "`date`: $service are started!"
    fi
  2. 添加ansible task

        ---
        - name: Deploy storm recovery script
          copy: src=storm-recovery dest=/usr/bin/storm-recovery mode=0755
          tags: guard
    
        - name: Add cron job for storm recovery
          cron: name="storm recovery" job="/usr/bin/storm-recovery" minute=*/5 state=present
          tags: guard
  3. 将该task任务加入到main.yml中 roles/storm_nimbus/tasks/main.yml

    - include: guard.yml
posted @ 2016-04-11 17:50  chenqiangzhishen  阅读(438)  评论(0编辑  收藏  举报