Demand:
Upload 3 shell scripts to the specified directory, set permissions to 755, owner, group Root
and set under Crontab
* * * * * /path/file
When it comes to machines, use Ansible to perform in batches.
involves copy, cron module
Copy Example:
Examples- name: example copying file with owner and permissions copy: src: /srv/myfiles/foo.conf dest: /etc/foo.conf owner: foo group: foo mode: 0644
Cron Example:
Examples# 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"
The final scenario is as follows:
---- hosts: ctijk remote_user: toptea become: yes become_method: sutasks:- name: transfer file to server copy: src: /tmp/iomonitor.sh dest: /opt/iomonitor.sh owner: root group: root mode: 0755- name: transfer file to server copy: src: /tmp/topmonitor.sh dest: /opt/topmonitor.sh owner: root group: root mode: 0755- name: transfer file to server copy: src: /tmp/cpumonitor.sh dest: /opt/cpumonitor.sh owner: root group: root mode: 0755- cron: name: "cti cpumonitor" minute: ‘*‘ job: "/opt/cpumonitor.sh"- cron: name: "cti iomonitor" minute: ‘*‘ job: "/opt/iomonitor.sh"- cron: name: "cti topmonitor" minute: ‘*‘ job: "/opt/topmonitor.sh"
Ansible Playboos implement upload files, create crontab