diff --git a/playbook/roles/upgrader/tasks/main.yml b/playbook/roles/upgrader/tasks/main.yml index 0f9ad099cd6798a2a6afa80c88dc8dd348fdfca9..92be6708e5e6c3fd86b3b1de3863fb6b2f76f66f 100644 --- a/playbook/roles/upgrader/tasks/main.yml +++ b/playbook/roles/upgrader/tasks/main.yml @@ -47,9 +47,9 @@ - file: path=/opt/upgrader/ state=directory mode=0755 - - shell: rm -rf /opt/upgrader/tmp + - set_fact: new_playbook=decompressed-playbook-{{ ansible_date_time.epoch }} - - shell: mkdir -p /opt/upgrader/tmp + - shell: mkdir -p /opt/upgrader/{{ new_playbook }} - name: Periodically download the latest playbook shell: /usr/local/bin/slapcache-download --destination=/opt/upgrader/archive.tar.gz @@ -57,22 +57,29 @@ - name: Uncompress shell: tar -xzvf /opt/upgrader/archive.tar.gz args: - chdir: /opt/upgrader/tmp + chdir: /opt/upgrader/{{ new_playbook }} - 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/{{ new_playbook }} && find . -type f ! -name 'sha256sum' -print0 | LC_ALL=C sort -z | xargs -0 sha256sum | sha256sum --check sha256sum + + - shell: rm -rf /opt/upgrader/tmp - - shell: cp -R /opt/upgrader/tmp /opt/upgrader/playbook + - shell: ln -s /opt/upgrader/{{ new_playbook }} /opt/upgrader/tmp + + - shell: cp -R /opt/upgrader/{{ new_playbook }} /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 +# If the machine stops before syncing playbook-tmp will be corrupted +# If playbook-tmp is written non-atomically it might get corrupted + - shell: sync && mv -T /opt/upgrader/tmp /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 + - shell: rm -rf $(ls -d1t decompressed-playbook-*|tail -n+2) + args: + chdir: /opt/upgrader - name: Save new archive MD5 stat: diff --git a/playbook/sha256sum b/playbook/sha256sum index 7627bc0dfd835945b42ca381bcf32ac928aeb90a..82458ba483d957c5a965c9dbc85301cda9dd2dc0 100644 --- a/playbook/sha256sum +++ b/playbook/sha256sum @@ -1 +1 @@ -65410415ae8c0b4439e310301f60a60eb3804b51ff1beb5b26fccae345c3534b - +42c69aa7bf6f035eba065c25aa79ec23e442e39d8603a2168edebac9dc2f91d1 -