模組文件

  1. 查詢 cron 模組文件。
    [deyu1@kvm19 ansible]$ ansible-doc cron
    
  2. 查詢 cron 模組文件的範例,2點及5點執行 "ls -alh > /dev/null"。
    [deyu1@kvm19 ansible]$ ansible-doc cron | grep ^EX -A55
    EXAMPLES:
    
    - name: Ensure a job that runs at 2 and 5 exists. Creates an entry like "0 5,2 * * ls -alh > /dev/null"
      cron:
        name: "check dirs"
        minute: "0"
        hour: "5,2"
        job: "ls -alh > /dev/null"
    
  3. 刪除名為 "an old job" 的例行性工作。
    - name: 'Ensure an old job is no longer present. Removes any job that is prefixed by "#Ansible: an old job" from the crontab'
      cron:
        name: "an old job"
        state: absent
    
  4. 新增一個cron job,在 reboot 時執行 "/some/job.sh"。
    - name: Creates an entry like "@reboot /some/job.sh"
      cron:
        name: "a job for reboot"
        special_time: reboot
        job: "/some/job.sh"
    
  5. 在 crontab 的最上方新增一行 "PATH=/opt/bin"。
    - name: Creates an entry like "PATH=/opt/bin" on top of crontab
      cron:
        name: PATH
        env: yes
        job: /opt/bin
    
  6. 在 PATH 宣告行後面新增一行 "APP_HOME=/src/app"。
    - name: Creates an entry like "APP_HOME=/srv/app" and insert it after PATH declaration
      cron:
        name: APP_HOME
        env: yes
        job: /srv/app
        insertafter: PATH
    
  7. 在 /etc/cron.d 目錄下新增一個例行性工作檔ansible_yum-autoupdate,每星期二12點整執行job。
    - name: Creates a cron file under /etc/cron.d
      cron:
        name: yum autoupdate
        weekday: 2
        minute: 0
        hour: 12
        user: root
        job: "YUMINTERACTIVE=0 /usr/sbin/yum-autoupdate"
        cron_file: ansible_yum-autoupdate
    
  8. 刪除 /etc/cron.d 目錄下的例行性工作檔ansible_yum-autoupdate
    - name: Removes a cron file from under /etc/cron.d
      cron:
        name: "yum autoupdate"
        cron_file: ansible_yum-autoupdate
        state: absent
    
  9. 刪除 crontab 的環境變數 "APP_HOME=/src/app"。
    - name: Removes "APP_HOME" environment variable from crontab
      cron:
        name: APP_HOME
        env: yes
        state: absent
    
  10. 建立一個不安全的 cron。
    - name: Create an insecure cron
      cron:
        path: /work
        owner: root
        group: root
        mode: '1777'