Commit db0d2246 authored by Rafael Monnerat's avatar Rafael Monnerat

playbook: Include proof of concept of upgrader role

parent 3d1c5f50
#!/bin/bash
if [ ! -f /etc/opt/slapcache.cfg ]; then
slapcache-conf
fi
DFILE="/opt/upgrader/"
TFILE="archive.tar.gz"
mkdir -p $DFILE
cd $DFILE
slapcache-download --destination=$TFILE
tar -xzvf $TFILE
md5sum $TFILE > "/opt/upgrader/next-upgrader-md5sum"
---
- file: path=/opt/upgrader/ state=directory mode=0755
- shell: rm -rf /opt/upgrader/playbook/
- file: path=/opt/upgrader/playbook/ state=directory mode=0755
- name: Periodically download the latest playbook
shell: slapcache-download --destination=/opt/upgrader/archive.tar.gz
- name: Uncompress
unarchive: src=/opt/upgrader/archive.tar.gz dest=/opt/upgrader/playbook/
- name: Save new archive MD5
stat: path=/opt/upgrader/archive.tar.gz
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 >> /opt/upgrader/latest_upgrade.log
when: lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature')
args:
chdir: /opt/upgrader/playbook/
- name: Upgrade Current Upgrade Signature
shell: cat /opt/upgrader/next-upgrade-signature > /opt/upgrader/current-upgrade-signature
when: lookup('file', '/opt/upgrader/next-upgrade-signature') != lookup('file', '/opt/upgrader/current-upgrade-signature')
- name: Set Cron
cron: name="Launch Upgrader" minute="0" hour="*/3" job='ansible-playbook upgrader-run.yml --with-vars "upgrader-playbook={{ upgrader_playbook }}" -i hosts >> /opt/upgrader/latest_upgrade.log'
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
roles:
- upgrader
- name: a play that runs entirely on the ansible host
hosts: 127.0.0.1
connection: local
vars:
- upgrader-playbook: vifib-upgrader.yml
- computer_name: noname
- slapostoken: notoken
vars_files:
- settings/vifib.yml
roles:
- { role: re6stnet-legacy, package_state: latest }
- { role: slapos, package_state: latest }
- { role: package, package_name: ntp, package_state: latest }
- { role: package, package_name: ntp, package_state: latest }
- vifib-server
- upgrader
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
hosts: 127.0.0.1 hosts: 127.0.0.1
connection: local connection: local
vars:
- upgrader-playbook: vifib-upgrader.yml
vars_files: vars_files:
- settings/vifib.yml - settings/vifib.yml
...@@ -21,4 +24,4 @@ ...@@ -21,4 +24,4 @@
- { role: slapos, package_state: present } - { role: slapos, package_state: present }
- { role: package, package_name: ntp, package_state: present } - { role: package, package_name: ntp, package_state: present }
- vifib-server - vifib-server
- upgrader
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