P
P
petrov_ruslan2018-07-14 00:33:26
Ansible
petrov_ruslan, 2018-07-14 00:33:26

How to create a job in cron using Ansible?

I want to create a playbook with the ability to record jobs in cron with running a script, but only at different times for all hosts.
There is this playbook:

---
- name: Create cron task
  hosts: testhost0
  
  tasks:
  - name: Add tasks to testhost0
    cron:
        name: "download tasks"
        minute: "0"
        hour: "1"
        job: "/home/userdir/./download.sh"

- name: Create cron task
  hosts: testhost1
  
  tasks:
  - name: Add tasks to testhost1
    cron:
        name: "download tasks"
        minute: "0"
        hour: "2"
        job: "/home/userdir/./download.sh"

etc

Everything works out only if some host was not available at that moment. If this happens, the task stops. Tried setting ignore_errors: yes, but it only works if there is an error, not when the host is not available.
Poke please how to do it, preferably with an example and a link to the documentation. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Shitskov, 2018-07-14
@Zarom

You write the playbook a little incorrectly to solve this problem. Place the necessary servers in the inventory and set different variables for them with the start time. After that, for this group of hosts, run a playbook that adds a task to the cron. You will get a playbook that works on all available hosts and with individual parameters, consisting of only one task

P
Puma Thailand, 2018-07-14
@opium

I seem to work out the norms with ignore EU
try to install the latest version

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question