1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
- file: path=/opt/upgrader state=directory mode=0755
- stat: path=/opt/upgrader/playbook
register: playbook_folder
- stat: path=/opt/upgrader/last-upgrade
register: last_upgrade
- shell: echo 1 > /opt/upgrader/last-upgrade
when: last_upgrade.stat.exists == False
- file: path=/opt/upgrader/ state=directory mode=0755
- shell: rm -rf /opt/upgrader/tmp
- shell: mkdir -p /opt/upgrader/tmp
- name: Periodically download the latest playbook
shell: /usr/local/bin/slapcache-download --destination=/opt/upgrader/archive.tar.gz
- name: Uncompress
shell: tar -xzvf /opt/upgrader/archive.tar.gz
args:
chdir: /opt/upgrader/tmp
- shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook
when: playbook_folder.stat.exists == False
- stat: path=/opt/upgrader/tmp/hosts
register: hosts_file
- shell: rm -rf /opt/upgrader/playbook-tmp
when: hosts_file.stat.exists == True
- shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook-tmp
when: hosts_file.stat.exists == True
- name: Save new archive MD5
stat:
path=/opt/upgrader/archive.tar.gz
get_md5=yes
register:
archive
- name: Update playbook md5
shell: echo {{ archive.stat.md5 }} > /opt/upgrader/next-upgrade-signature
- name: Stat Current Upgrade Signature
file: path=/opt/upgrader/current-upgrade-signature state=touch mode="0666"
- name: Get /opt/upgrader/next-upgrade-signature content
shell: cat /opt/upgrader/next-upgrade-signature
register:
next_upgrade_signature
- name: Get /opt/upgrader/current-upgrade-signature content
shell: cat /opt/upgrader/current-upgrade-signature
register:
current_upgrade_signature
- name: Do upgrade
shell: ansible-playbook {{ upgrader_playbook }} -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log
when: (upgrade_after > lookup('file', '/opt/upgrader/last-upgrade')|int ) and (lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature'))
args:
chdir: /opt/upgrader/playbook-tmp/
- name: Set Cron
cron: name="Launch Upgrader with ansible" minute="0" hour="*/3" job='rm -rf /opt/upgrader/playbook && cp -R /opt/upgrader/playbook-tmp /opt/upgrader/playbook && cd /opt/upgrader/playbook && PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin ansible-playbook upgrader-run.yml --extra-vars "upgrader_playbook={{ upgrader_playbook }}" -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log'
- cron: name="Launch Upgrader" state=absent
- name: Upgrade Current Upgrade Signature
shell: cat /opt/upgrader/next-upgrade-signature > /opt/upgrader/current-upgrade-signature
when: (upgrade_after > lookup('file', '/opt/upgrader/last-upgrade')|int ) and (lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature'))
- shell: echo {{ ansible_date_time.epoch }} > /opt/upgrader/last-upgrade
when: (upgrade_after > lookup('file', '/opt/upgrader/last-upgrade')|int )
- include: remove-legacy.yml