Posted on

using Ansible to maintain remote files and crontabs

Using Ansible to maintain the checks discussed in an earlier post and update the crontab.

This expects the servername(s) and the minutes for the crontab because I don’t want all cron’s running at the same time. I can then call this for each host, with the times for the crontab maintained in the config management tool.

ansible-playbook remote-checks.yml --extra-vars "hosts=$1 minutes=$2"

And remote-checks.yml copies the check file for each server from a source location:

- hosts: '{{ hosts }}'
become_user: root
become: yes
servername: "{{ansible_hostname|lower}}"
minutes: "{{minutes}}"
- name: copy script containing list of checks
copy: src=/home/ansible/source/checks/{{servername}}/ dest=/usr/local/nagios/passive/ owner=nagios group=nagios mode=0755
- name: "passive 10min checks"
name: "passice checks every 10 minutes"
user: nagios
minute: "{{minutes}}"
hour: "*"
job: "/usr/local/nagios/passive/"