Fix destroy of opensm and docker-registry containers

Now also removes docker volumes
This commit is contained in:
Mark Goddard 2017-08-22 13:59:49 +00:00
parent e5f889baaa
commit 7d7dc486a4
4 changed files with 52 additions and 4 deletions

View File

@ -8,6 +8,6 @@
read_only: "{{ item.value.read_only | default(omit) }}"
restart_policy: "{{ docker_registry_restart_policy }}"
restart_retries: "{{ docker_registry_restart_retries }}"
state: "{{ 'started' if item.value.enabled and action != 'destroy' | bool else 'absent' }}"
state: "{{ (item.value.enabled and action != 'destroy') | ternary('started', 'absent') }}"
volumes: "{{ item.value.volumes }}"
with_dict: "{{ docker_registry_services }}"

View File

@ -1 +0,0 @@
deploy.yml

View File

@ -0,0 +1,25 @@
---
- include: deploy.yml
- name: Check whether docker registry volumes are present
command: docker volume inspect {{ volume }}
changed_when: False
with_subelements:
- "{{ docker_registry_services }}"
- volumes
when: "'/' not in volume"
failed_when:
- volume_result.rc != 0
- "'No such volume' not in volume_result.stderr"
vars:
volume: "{{ item.1.split(':')[0] }}"
register: volume_result
- name: Ensure docker registry volumes are absent
command: docker volume rm {{ volume }}
with_items: "{{ volume_result.results }}"
when:
- not item | skipped
- item.rc == 0
vars:
volume: "{{ item.item.1.split(':')[0] }}"

View File

@ -8,6 +8,6 @@
read_only: "{{ item.value.read_only | default(omit) }}"
restart_policy: "{{ opensm_restart_policy }}"
restart_retries: "{{ opensm_restart_retries }}"
state: "{{ 'started' if item.value.enabled and action != 'destroy' | bool else 'absent' }}"
state: "{{ (item.value.enabled and action != 'destroy') | ternary('started', 'absent') }}"
volumes: "{{ item.value.volumes }}"
with_dict: "{{ opensm_services }}"

View File

@ -1 +0,0 @@
deploy.yml

View File

@ -0,0 +1,25 @@
---
- include: deploy.yml
- name: Check whether OpenSM volumes are present
command: docker volume inspect {{ volume }}
changed_when: False
with_subelements:
- "{{ opensm_services }}"
- volumes
when: "'/' not in volume"
failed_when:
- volume_result.rc != 0
- "'No such volume' not in volume_result.stderr"
vars:
volume: "{{ item.1.split(':')[0] }}"
register: volume_result
- name: Ensure OpenSM volumes are absent
command: docker volume rm {{ volume }}
with_items: "{{ volume_result.results }}"
when:
- not item | skipped
- item.rc == 0
vars:
volume: "{{ item.item.1.split(':')[0] }}"