From bc3cac8e2ad315da174881122d0955acebcb18ab Mon Sep 17 00:00:00 2001 From: Chris Croome <chris@webarchitects.co.uk> Date: Wed, 27 Sep 2017 10:00:25 +0100 Subject: [PATCH] Docker upgrade playbook added --- README.md | 19 +++------ discourse_upgrade.yml | 2 +- docker_upgrade.yml | 6 +++ roles/docker-upgrade/tasks/main.yml | 64 +++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 14 deletions(-) create mode 100644 docker_upgrade.yml create mode 100644 roles/docker-upgrade/tasks/main.yml diff --git a/README.md b/README.md index db01bbf..59f2033 100644 --- a/README.md +++ b/README.md @@ -26,22 +26,15 @@ ansible-playbook -u root discourse_upgrade.yml -i "${SERVERNAME}," -e "hostname= ## Docker Upgrade -Every 3 months there is a new version of `docker-ce` released, the steps to upgrade (this could potentially be written as a Ansible Playbook: +At least every 3 months there is a new version of `docker-ce` released, see the +[release notes](https://docs.docker.com/release-notes/docker-ce/), to upgrade +Docker CE use this playbook: ```bash -sudo -i -su - discourse -cd /var/discourse -./launcher app stop -exit -apt-get update -apt-get upgrade -service docker status # check the uptime and that it is running -su - discourse -cd /var/discourse -./launcher app start +export SERVERNAME="community.coops.tech" +ansible-playbook -u root docker_upgrade.yml -i "${SERVERNAME}," -e "hostname=${SERVERNAME}" ``` - + ## Discourse Install Ansible Playbooks to install diff --git a/discourse_upgrade.yml b/discourse_upgrade.yml index 3b58d6e..6d2f280 100644 --- a/discourse_upgrade.yml +++ b/discourse_upgrade.yml @@ -1,5 +1,5 @@ --- -- name: Install Discourse +- name: Upgrade Discourse hosts: "{{ hostname }}" roles: diff --git a/docker_upgrade.yml b/docker_upgrade.yml new file mode 100644 index 0000000..a354472 --- /dev/null +++ b/docker_upgrade.yml @@ -0,0 +1,6 @@ +--- +- name: Upgrade Docker CE + hosts: "{{ hostname }}" + + roles: + - docker-upgrade diff --git a/roles/docker-upgrade/tasks/main.yml b/roles/docker-upgrade/tasks/main.yml new file mode 100644 index 0000000..39f3510 --- /dev/null +++ b/roles/docker-upgrade/tasks/main.yml @@ -0,0 +1,64 @@ +--- +- name: Stop the Discourse container + command: bash launcher stop app + args: + chdir: "/var/discourse" + become: yes + become_user: discourse + +- name: Update apt package list + apt: + update_cache: yes + +- name: Check if the Webarchitects logchange script is installed + command: which logchange + register: logchange + +- block: + + - name: Get a list of the updates + shell: "apt-show-versions -b -u | xargs" + register: apt_updates + + - name: Record the updates in the /root/Changelog + command: 'logchange "{{ apt_updates.stdout }} : Updated"' + when: apt_updates.stdout != "" + + when: logchange.stdout != "" + +- name: Check if the Munin apt state file exists + stat: + path: "/var/lib/munin-node/plugin-state/nobody/plugin-apt.state" + register: munin_apt_state + +- block: + + - name: Delete the Munin apt state file + file: + dest: "/var/lib/munin-node/plugin-state/nobody/plugin-apt.state" + state: absent + + - name: Update the Munin apt state file + command: munin-run apt_all + + when: munin_apt_state.stat.exists == True + +- name: Update all packages + apt: + upgrade: dist + autoclean: yes + +- name: Restart Docker CE + service: + name: docker + state: restarted + +- name: Start the Discourse container + command: bash launcher start app + args: + chdir: "/var/discourse" + become: yes + become_user: discourse + + + -- GitLab