Crons on a collection of servers

22 views
Skip to first unread message

Ed Greenberg

unread,
Mar 8, 2017, 11:27:25 AM3/8/17
to Ansible Project
We have a collection of load balanced web servers, and we have cron jobs spread across the server base.

I would like to manage these cron jobs in Ansible. 

The current state is to have all the cron jobs on all the servers, disabled, and then to selectively enable the ones that need to run on each server.

On my test server, I rolled out all the cron jobs as state=present disabled=true and got all the cron jobs, properly commented out.

I can do a play as follows:


    - name: cron Update Webmin
      cron:
        user: root
        state: present
        name: "Update Webmin"
        minute: "10"
        hour: "10"
        day: "*"
        month: "*"
        weekday: "2"
        job: "/etc/webmin/package-updates/update.pl"
      when: ansible_hostname == 'web-node-1'

But when I go into the playbook and change web-host-1 to web-host-2, that won't remove the job from web1.

So my current thought is:
    - name: cron Update Webmin
      cron:
        user: root
        state: present
        disabled: true 
        name: "Update Webmin"
        minute: "10"
        hour: "10"
        day: "*"
        month: "*"
        weekday: "2"
        job: "/etc/webmin/package-updates/update.pl"


    - name: cron Update Webmin
      cron:
        user: root
        state: present
        name: "Update Webmin"
        minute: "10"
        hour: "10"
        day: "*"
        month: "*"
        weekday: "2"
        job: "/etc/webmin/package-updates/update.pl"
      when: ansible_hostname == 'web-node-1'

This should roll all the jobs to all the servers, then enable them only where needed.

So, for a reality check, does this seem the best method?

Thanks,

Ed G


Dick Davies

unread,
Mar 8, 2017, 11:32:30 AM3/8/17
to ansible list
Why don't you just set disabled: as a var, and then set that either
true or false on each server/group
as needed?
> --
> You received this message because you are subscribed to the Google Groups
> "Ansible Project" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to ansible-proje...@googlegroups.com.
> To post to this group, send email to ansible...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/6e8f8017-e4f2-43ce-97b7-e6b684f01089%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages