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 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
沒有留言:
張貼留言