2024年10月2日 星期三

【IT Notes】RHCE測驗第十七題 Configure a cron job

Create a playbook called /home/student/ansible/cron.yml that runs on all managed hosts and creates a cron job for user student as follows:

  • The user natasha must configure a cron job that runs every 2 minutes and executes logger “Hello World”

 【題前說明】

完成前面幾題以後,最後這一題算是相對簡單的,只需要在每台主機上建立使用者natasha,並以其身分設定每兩分鐘執行一遍的排程工作,任務就算結束了。

 一.解題過程:

[student@workstation ansible]$ vim cron.yml
---
- name: create cronjob for an user
  hosts: all
  tasks:
    - name: create user natasha
      user:
        name: natasha
        state: present
    - name: create cron job
      cron:
        name: "logger for natasha"
        minute: '*/2'
        user: natasha
        job: logger "Hello World"


二.驗證結果

[student@workstation ansible]$ ansible-playbook -C cron.yml

[student@workstation ansible]$ ansible-playbook cron.yml


[student@workstation ansible]$ ansible all -m shell -a 'crontab -u natasha -l'



三.恢復解題前的環境

[student@workstation ansible]$ vim 17-lab-cron-stop.yml
---
- name: remove job
  hosts: all
  tasks:
    - name: remove cron jon
      cron:
        name: "job , 2 minute /per"
        state: absent
        user: natasha
        job: logger "Hello World"

    - name: remove user
      user:
        name: natasha
        state: absent

- name: remove cron.yml
  hosts: 127.0.0.1
  tasks:
    - name: remove cron.yml
      file:
        path: /home/student/ansible/cron.yml
        state: absent


沒有留言:

張貼留言

【IT Notes】透過api移轉Gmail到Exchange

 在雲端裡面串接api不是一件很好學的技術,第一次有機會學習到將GWS的Gmail信件全部轉移到M365的Exchange,其實方法很多種,像以前用的pst檔匯出轉移的方式等,但透過api串接,可以批次和排程轉移,是非常方便且準確的作法。唯一讓人感到困難的是學習成本不小,通常需要...