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


沒有留言:

張貼留言

【當兵回憶】八里連

 在我心目中新兵日記是天花板等級的軍教片,並不是說沒有比它更好的作品,只是因為它的在拍攝的背景和時間,也正是我在服兵役的同時,老婆很多次好奇問我,為什麼我總是放在YouTube的新兵日記直播,我都說我只放在有個聲音在,我沒有真正在看,但這行為仔細想想也好多年了吧!台詞聽到我都會背...