From 1694340dfc0d2ba346eac60501dde4168ba10324 Mon Sep 17 00:00:00 2001 From: AndrewPaglusch Date: Fri, 17 Dec 2021 23:27:23 -0600 Subject: [PATCH] handle version upgrades; new handler handling --- handlers/main.yml | 4 ++++ tasks/lighthouse.yml | 2 +- tasks/nebula.yml | 20 +++++++++++++++++++- tasks/node.yml | 2 +- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/handlers/main.yml b/handlers/main.yml index 3d7da35..ea6d622 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -2,8 +2,12 @@ systemd: name: nebula state: restarted + when: inventory_hostname not in groups['nebula_lighthouse'] + listen: "restart nebula" - name: Restart Lighthouse systemd: name: lighthouse state: restarted + when: inventory_hostname in groups['nebula_lighthouse'] + listen: "restart nebula" diff --git a/tasks/lighthouse.yml b/tasks/lighthouse.yml index ea00590..bf6738b 100644 --- a/tasks/lighthouse.yml +++ b/tasks/lighthouse.yml @@ -18,7 +18,7 @@ owner: root group: root mode: '0400' - notify: Restart Lighthouse + notify: restart nebula - name: Ensure lighthouse service exists template: diff --git a/tasks/nebula.yml b/tasks/nebula.yml index 977a3c2..cb0368d 100644 --- a/tasks/nebula.yml +++ b/tasks/nebula.yml @@ -6,12 +6,30 @@ owner: root group: root +- name: Check for existing Nebula install + stat: + path: '/opt/nebula/nebula' + register: installed_nebula_stats + +- name: Get Nebula version (if installed) + command: "/opt/nebula/nebula -version" + register: installed_nebula_version_out + changed_when: False + failed_when: False + when: installed_nebula_stats.stat.exists + +- name: Extract Nebula version from command output + set_fact: + installed_nebula_version: "{{ installed_nebula_version_out.stdout.split(' ')[1] }}" + when: installed_nebula_stats.stat.exists + - name: Download & Extract Nebula unarchive: src: "https://github.com/slackhq/nebula/releases/download/v{{ nebula_version }}/nebula-linux-{{ nebula_architectures[ansible_architecture] }}.tar.gz" dest: "/opt/nebula" remote_src: yes - creates: '/opt/nebula/nebula' + when: (installed_nebula_version|default(nebula_version) != nebula_version) or (not installed_nebula_stats.stat.exists) + notify: restart nebula - name: Ensure Nebula binaries permissions are correct file: diff --git a/tasks/node.yml b/tasks/node.yml index e4ed33b..f7e3eec 100644 --- a/tasks/node.yml +++ b/tasks/node.yml @@ -46,7 +46,7 @@ owner: root group: root mode: '0400' - notify: Restart Nebula + notify: restart nebula - name: Ensure Nebula service exists template: