tripleo-ansible/tripleo_ansible/roles/tripleo-container-rm/tasks/tripleo_podman_container_rm...

80 lines
2.4 KiB
YAML

---
# 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.
- name: "check if {{ container }} service healthcheck exists in systemd"
stat:
path: "/etc/systemd/system/tripleo_{{ container }}_healthcheck.service"
register: systemd_healthcheck_exists
- name: "tear-down {{ container }} healthcheck"
when:
- systemd_healthcheck_exists.stat.exists
block:
- name: "stop and disable {{ container }} healthcheck"
systemd:
name: "tripleo_{{ container }}_healthcheck"
state: stopped
enabled: false
- name: "remove {{ container }} healthcheck service"
file:
path: "/etc/systemd/system/tripleo_{{ container }}_healthcheck.service"
state: absent
- name: "remove {{ container }} healthcheck timer"
file:
path: "/etc/systemd/system/tripleo_{{ container }}_healthcheck.timer"
state: absent
- name: "check if {{ container }} service exists in systemd"
stat:
path: "/etc/systemd/system/tripleo_{{ container }}.service"
register: systemd_exists
- name: "tear-down {{ container }} container"
when:
- systemd_exists.stat.exists
block:
- name: "stop and disable {{ container }}"
systemd:
name: "tripleo_{{ container }}"
state: stopped
enabled: false
- name: "remove {{ container }} systemd service"
file:
path: "/etc/systemd/system/tripleo_{{ container }}.service"
state: absent
- name: Reload systemd services if needed
when:
- systemd_healthcheck_exists.stat.exists or systemd_exists.stat.exists
systemd:
daemon_reload: true
- name: "stat {{ container }} container"
command: "podman container exists {{ container }}"
failed_when: false
changed_when: false
register: stat_container
- name: Stop and remove container
command: "podman container rm --force {{ container }}"
changed_when: true
when:
- stat_container.rc == 0