-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcronjob.yml
23 lines (20 loc) · 1.05 KB
/
cronjob.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
---
- name: Calculate the time 24 hours from now
ansible.builtin.set_fact:
cron_time: "{{ lookup('pipe', 'date -d \"+1 hours\" +\"%M %H %d %m %Y\"') }}"
- name: Create the cron job
ansible.builtin.cron:
state: present
name: "script_cron {{ target_vcs }}"
user: "{{ lookup('env', 'USER') }}"
minute: "{{ cron_time.split()[0] }}"
hour: "{{ cron_time.split()[1] }}"
day: "{{ cron_time.split()[2] }}"
month: "{{ cron_time.split()[3] }}"
job: source ~/nested.source && cd ~/nested-ova-ansible-ci/ ; ansible-playbook -i hosts main.yml --extra-var cleanupcron=true --extra-var version={{ '"' }}{{ version }}{{ '"' }} --extra-var='{"target_hosts"{{ ":" }} {{ target_hosts}}}' --extra-var='{"target_vcs"{{ ":"}} {{ target_vcs}} }' --extra-var removevsphere=true -t removevsphere >> /tmp/{{ target_vcs[0] | replace('[', '') | replace(']', '') | regex_replace("'", '') }}.log 2>&1
when: createcron | bool
- name: Remove the cron job
ansible.builtin.cron:
state: absent
name: "script_cron {{ target_vcs }}"
when: cleanupcron | bool