All Linux HowTo's

Ansible Playbook to add script to Cron.monthly (or whatever) in Redhat/CentOS

This playbook will add the script “myscript.sh” to the target machine(s) “/etc/cron.monthly” directory thereby having it run each month by cron. You can simply change the location to have it go into one of the other cron.x locations. I’ve used ansible version “ansible 1.9.4”.

---
- hosts: all

  sudo: yes

  tasks:

  - name: install selinux bindings
    yum: name=libselinux-python state=present

  - copy: src=/ansible/files/myscript.sh dest=/etc/cron.monthly/myscript.sh owner=root group=root mode=0755

For more (getting started) see the article here: http://www.agix.com.au/use-ansible-to-add-users-and-their-ssh-public-keys-on-multiple-linux-servers/

Share This:

Leave a Reply

Your email address will not be published. Required fields are marked *