diff --git a/clear-data.yml b/clear-data.yml new file mode 100644 index 0000000..e1bbabc --- /dev/null +++ b/clear-data.yml @@ -0,0 +1,64 @@ +--- +- name: Delete Consul data + hosts: consul_instances + + tasks: + - name: Stop consul + systemd: + name: consul + state: stopped + become: true + + - name: Stop vault + systemd: + name: consul + state: stopped + become: true + + - name: Remove data dir + file: + path: /opt/consul + state: absent + become: true + +- name: Delete Nomad data + hosts: nomad_instances + + tasks: + - name: Stop nomad + systemd: + name: nomad + state: stopped + become: true + + - name: Kill nomad + shell: + cmd: systemctl kill nomad + become: true + + - name: Stop all containers + shell: + cmd: docker ps -a | awk '/^[0-9abcdef]/{print $1}' | xargs -r docker stop + become: true + + - name: Remove all containers + shell: + cmd: docker ps -a | awk '/^[0-9abcdef]/{print $1}' | xargs -r docker rm + become: true + + - name: Unmount secrets + shell: + cmd: mount | awk '/nomad/ {print $3}' | xargs -n1 -r umount + become: true + + - name: Remove data dir + file: + path: /var/nomad + state: absent + become: true + + - name: Remove data dir + file: + path: /opt/nomad/data + state: absent + become: true