Implement tripleo-docker-rm role

tripleo-docker-rm
=================

An Ansible role to remove Docker containers when Podman is enabled.

Requirements
------------

It requires python-docker on the host.

Role variables
--------------

- container_cli: -- Name of the Container CLI tool (default to docker).
- containers_to_rm: -- List of containers to remove.

Example Playbook
----------------

Sample playbook to call the role:

  - name: Remove Nova API docker containers
    hosts: all
    roles:
      - tripleo-docker-rm
    vars:
      containers_to_rm:
        - nova_api
        - nova_api_cron
      container_cli: podman

This role will be consummed by THT in post_upgrade_tasks.

Change-Id: I03ad922c61ddd0b4a34935e1e17c0b37cd71ee03
This commit is contained in:
Emilien Macchi 2018-11-02 10:39:04 -04:00
parent b031901a0e
commit 978088904d
4 changed files with 64 additions and 0 deletions

View File

@ -0,0 +1,5 @@
---
features:
- |
The new tripleo-docker-rm will be useful to remove the containers that
were managed by Docker and that are now managed by Podman.

View File

@ -0,0 +1,40 @@
tripleo-docker-rm
=================
An Ansible role to remove Docker containers when Podman is enabled.
Requirements
------------
It requires python-docker on the host.
Role variables
--------------
- container_cli: -- Name of the Container CLI tool (default to docker).
- containers_to_rm: -- List of containers to remove.
Example Playbook
----------------
Sample playbook to call the role:
- name: Remove Nova API docker containers
hosts: all
roles:
- tripleo-docker-rm
vars:
containers_to_rm:
- nova_api
- nova_api_cron
container_cli: podman
License
-------
Free software: Apache License (2.0)
Author Information
------------------
OpenStack TripleO team

View File

@ -0,0 +1,2 @@
---
container_cli: docker

View File

@ -0,0 +1,17 @@
---
- name: Check if docker is installed
stat:
path: /usr/bin/docker
register: docker_path_stat
- set_fact:
docker_installed: "{{ docker_path_stat.results | map(attribute='stat') | map(attribute='exists') is any }}"
- name: remove "{{ containers_to_rm|join(', ') }}" containers
docker_container:
name: "{{ item }}"
state: absent
when:
- container_cli == 'podman'
- docker_installed
with_items: "{{ containers_to_rm }}"