FuzzyAmi
FuzzyAmi

Reputation: 8147

Ansible: setup a cron job on one host

I'm deploying a 2-hosts service that also needs to setup a cron job. This job should only be run on one of the two machines (I dont care which). what's the easiest way to do so?

any better ideas?

Upvotes: 3

Views: 1782

Answers (1)

techraf
techraf

Reputation: 68559

I know that the shell module in Ansible supports "run_once", but the cron module does not.

Wrong. run_once is a property of a task, not of action modules.

Use cron module and set run_once for the task (mind the indentation level), for example:

- cron:
    name: "check dirs"
    minute: "0"
    hour: "5,2"
    job: "ls -alh > /dev/null"
  run_once: true

Upvotes: 3

Related Questions