tripleo_container_manage: remove podman/delete.yml and use another role

Re-use tripleo_container_rm role to remove the containers.
This role was doing the same thing as tasks/podman/delete.yml:

- remove healthcheck
- remove systemd service
- remove container

It reduces the duplication and re-use what we can from other roles.

Change-Id: Ibea31bb738fac4608b01cfe035e6c248b488aa09
This commit is contained in:
Emilien Macchi 2020-02-17 10:21:50 -05:00
parent 51b55bc901
commit 78cac0012a
3 changed files with 17 additions and 87 deletions

View File

@ -23,8 +23,11 @@
- name: "Delete orphan containers managed by Podman for {{ tripleo_container_manage_config }}"
when:
- tripleo_container_manage_cli == 'podman'
include_tasks: podman/delete.yml
loop: >-
{{ podman_containers.containers | needs_delete(config=all_containers_hash,
config_id=tripleo_container_manage_config_id, check_config=False) }}
- tripleo_container_manage_systemd_teardown | bool
include_role:
name: tripleo_container_rm
vars:
tripleo_container_cli: "{{ tripleo_container_manage_cli }}"
tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=all_containers_hash,
config_id=tripleo_container_manage_config_id, check_config=False) }}

View File

@ -16,11 +16,15 @@
- name: "Tear-down containers that need to be re-created (new-config detected)"
when:
- tripleo_container_manage_cli == 'podman'
include_tasks: podman/delete.yml
loop: >
{{ podman_containers.containers | needs_delete(config=batched_container_data|haskey(attribute='action', reverse=True)|singledict,
config_id=tripleo_container_manage_config_id, clean_orphans=False) }}
- tripleo_container_manage_systemd_teardown | bool
include_role:
name: tripleo_container_rm
vars:
tripleo_container_cli: "{{ tripleo_container_manage_cli }}"
tripleo_containers_to_rm: >-
{{ podman_containers.containers | needs_delete(config=batched_container_data|
haskey(attribute='action', reverse=True)|singledict,
config_id=tripleo_container_manage_config_id, clean_orphans=False) }}
- name: "Async container create/run"
async: "{{ (not ansible_check_mode | bool) | ternary('600', omit) }}"

View File

@ -1,77 +0,0 @@
---
# Copyright 2019 Red Hat, Inc.
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
# This playbook is a "best effort" way to remove a container from a host.
# It'll try to remove the healthcheck, service and then container without
# much validation in case things failed in the middle.
- name: "Disable systemd resources for {{ item }}"
when:
- tripleo_container_manage_systemd_teardown | bool
block:
- name: "Remove systemd healthcheck for {{ item }}"
block:
- name: "Stop and disable systemd timer for {{ item }}"
systemd:
state: stopped
name: "tripleo_{{ item }}_healthcheck.timer"
enabled: false
ignore_errors: true
- name: "Delete systemd timer file for {{ item }}"
file:
path: "/etc/systemd/system/tripleo_{{ item }}_healthcheck.timer"
state: absent
register: systemd_timer_deleted
- name: "Stop and disable systemd healthcheck for {{ item }}"
systemd:
state: stopped
name: "tripleo_{{ item }}_healthcheck.service"
enabled: false
ignore_errors: true
- name: "Delete systemd healthcheck file for {{ item }}"
file:
path: "/etc/systemd/system/tripleo_{{ item }}_healthcheck.service"
state: absent
register: systemd_healthcheck_deleted
- name: Force systemd to reread configs
systemd:
daemon_reload: true
when: systemd_timer_deleted.changed or systemd_healthcheck_deleted.changed
- name: "Stop and disable systemd service for {{ item }}"
systemd:
state: stopped
name: "tripleo_{{ item }}.service"
enabled: false
ignore_errors: true
- name: "Delete systemd unit file for {{ item }}"
file:
path: "/etc/systemd/system/tripleo_{{ item }}.service"
state: absent
register: systemd_file_deleted
- name: "Remove trailing .requires for {{ item }}"
file:
path: "/etc/systemd/system/tripleo_{{ item }}.requires"
state: absent
register: systemd_requires_deleted
- name: Force systemd to reread configs
systemd:
daemon_reload: true
when: systemd_file_deleted.changed or systemd_requires_deleted.changed
- name: "Remove container {{ item }}"
podman_container:
name: "{{ item }}"
state: absent