Commit 31f31b3d authored by Joanne Hugé's avatar Joanne Hugé

playbook/upgrader: avoid playbook-tmp getting corrupted

We had several cases of playbook-tmp becoming empty when
machines were unplugged at the wrong time. This happenned
because data was still in the buffer when machines were
unplugged.

The solution is to do a sync and then atomically change
playbook-tmp
parent b90ce61f
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
when: extra_playbook == "ors.yml" when: extra_playbook == "ors.yml"
- name: Set Cron to repeat until success - name: Set Cron to repeat until success
cron: name="Repeat until success" minute="*/5" hour="*" job="curl -fIs $(grep "^deb" /etc/apt/sources.list| cut -f2 -d' ' | head -n1) && flock -n /opt/upgrader/ansible.lock -c \"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 'extra_playbook={{ extra_playbook }} upgrader_playbook={{ upgrader_playbook }} repeat_until_success={{ repeat_until_success }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_repeat_upgrade.log >> /opt/upgrader/latest_repeat_upgrade.log\"" cron: name="Repeat until success" minute="*/5" hour="*" job="curl -fIs $(grep "^deb" /etc/apt/sources.list| cut -f2 -d' ' | head -n1) && flock -n /opt/upgrader/ansible.lock -c \"cd /opt/upgrader/playbook && PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin ansible-playbook upgrader-run.yml --extra-vars 'extra_playbook={{ extra_playbook }} upgrader_playbook={{ upgrader_playbook }} repeat_until_success={{ repeat_until_success }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_repeat_upgrade.log >> /opt/upgrader/latest_repeat_upgrade.log\""
when: repeat_until_success | bool when: repeat_until_success | bool
- name: Get monitor private directory path - name: Get monitor private directory path
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
- name: Periodically download the latest playbook - name: Periodically download the latest playbook
shell: /usr/local/bin/slapcache-download --destination=/opt/upgrader/archive.tar.gz shell: /usr/local/bin/slapcache-download --destination=/opt/upgrader/archive.tar.gz
- name: Uncompress - name: Uncompress latest playbook to tmp
shell: tar -xzvf /opt/upgrader/archive.tar.gz shell: tar -xzvf /opt/upgrader/archive.tar.gz
args: args:
chdir: /opt/upgrader/tmp chdir: /opt/upgrader/tmp
...@@ -62,16 +62,22 @@ ...@@ -62,16 +62,22 @@
- name: Check uncompressed archive sha256sum - name: Check uncompressed archive sha256sum
shell: cd /opt/upgrader/tmp && find . -type f ! -name 'sha256sum' -print0 | LC_ALL=C sort -z | xargs -0 sha256sum | sha256sum --check sha256sum shell: cd /opt/upgrader/tmp && find . -type f ! -name 'sha256sum' -print0 | LC_ALL=C sort -z | xargs -0 sha256sum | sha256sum --check sha256sum
- name: Sync disk
shell: sync
- shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook - shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook
when: playbook_folder.stat.exists == False when: playbook_folder.stat.exists == False
- stat: path=/opt/upgrader/tmp/hosts - stat: path=/opt/upgrader/tmp/hosts
register: hosts_file register: hosts_file
- shell: rm -rf /opt/upgrader/playbook-tmp - name: Move the latest playbook to playbook-tmp
shell: rm -rf playbook.todelete ; mv playbook-tmp playbook.todelete ; mv tmp playbook-tmp
args:
chdir: /opt/upgrader
when: hosts_file.stat.exists == True when: hosts_file.stat.exists == True
- shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook-tmp - shell: rm -rf /opt/upgrader/playbook.todelete
when: hosts_file.stat.exists == True when: hosts_file.stat.exists == True
- name: Save new archive MD5 - name: Save new archive MD5
...@@ -136,7 +142,7 @@ ...@@ -136,7 +142,7 @@
chdir: /opt/upgrader/playbook-tmp/ chdir: /opt/upgrader/playbook-tmp/
- name: Set Cron - name: Set Cron
cron: name="Launch Upgrader with ansible" minute="{{ period_minute }}" hour="{{ period_hour }}" job="flock -n /opt/upgrader/ansible.lock -c \"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 'period_minute={{ period_minute }} period_hour={{ period_hour }} upgrader_playbook={{ upgrader_playbook }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log\"" cron: name="Launch Upgrader with ansible" minute="{{ period_minute }}" hour="{{ period_hour }}" job="flock -n /opt/upgrader/ansible.lock -c \" [ -d /opt/upgrader/playbook-tmp ] && { rm -rf /opt/upgrader/playbook ; mv /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 'period_minute={{ period_minute }} period_hour={{ period_hour }} upgrader_playbook={{ upgrader_playbook }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_upgrade.log >> /opt/upgrader/latest_upgrade.log\""
when: repeat_until_success | bool == False when: repeat_until_success | bool == False
- cron: name="Launch Upgrader" state=absent - cron: name="Launch Upgrader" state=absent
...@@ -168,5 +174,5 @@ ...@@ -168,5 +174,5 @@
when: repeat_until_success | bool when: repeat_until_success | bool
- name: Set Anacron after successful playbook run - name: Set Anacron after successful playbook run
lineinfile: dest=/etc/anacrontab regexp="^[0-9]+ [0-9]+ extra.playbook (.*)" line="1 10 extra.playbook curl -fIs $(grep "^deb" /etc/apt/sources.list| cut -f2 -d' ' | head -n1) && flock -n /opt/upgrader/ansible.lock -c \"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 'extra_playbook={{ extra_playbook }} upgrader_playbook={{ upgrader_playbook }} repeat_until_success={{ repeat_until_success }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log\"" state=present lineinfile: dest=/etc/anacrontab regexp="^[0-9]+ [0-9]+ extra.playbook (.*)" line="1 10 extra.playbook curl -fIs $(grep "^deb" /etc/apt/sources.list| cut -f2 -d' ' | head -n1) && flock -n /opt/upgrader/ansible.lock -c \"[ -d /opt/upgrader/playbook-tmp ] && { rm -rf /opt/upgrader/playbook ; mv /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 'extra_playbook={{ extra_playbook }} upgrader_playbook={{ upgrader_playbook }} repeat_until_success={{ repeat_until_success }} upgrade_kernel={{ upgrade_kernel | default(False) == True }} playbook_report={{ playbook_report_fact }}' -i hosts 2>>/opt/upgrader/latest_daily_upgrade.log >> /opt/upgrader/latest_daily_upgrade.log\"" state=present
when: repeat_until_success | bool when: repeat_until_success | bool
f2ded4ea43a9b05bd99bc07fdb07c12a51bf0aa1fe07c83a24d5ac1e8322ac85 - 135a721175653131c8099e9d834a268744110206c558140f6a49cc1bcc8c4158 -
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment