Add podman container roles

This commit is contained in:
2019-12-28 20:07:15 -05:00
parent 0e5119bc6a
commit 8c8d1f9771
20 changed files with 581 additions and 0 deletions

View File

@@ -0,0 +1,63 @@
Container Image Cleanup
=======================
Periodicly cleans up all unused container images from host. Role sets up cron
job based on whether podman or docker is installed.
Requirements
------------
Role checks if either Podman or Docker is installed on host before installing cronjob.
Role Variables
--------------
There are variables in defaults/main.yml for timing of cronjob,
as well as path to binaries for docker and podman to check for.
* **podman_prune_cronjob_special_time**
see special_time options https://docs.ansible.com/ansible/latest/modules/cron_module.html
* **docker_prune_cronjob_special_time**
see special_time options https://docs.ansible.com/ansible/latest/modules/cron_module.html
* **podman_prune_opts**
podman system prune options, e.g. "--all --force"
* **docker_prune_opts:**
docker image prune options, e.g. "--all --force"
* **podman_path:**
where to look for podman executable, e.g: /usr/bin/podman
* **docker_path:**
where to look for docker executable, e.g: /usr/bin/docker
Dependencies
------------
No dependencies.
Example Playbook
----------------
```
- name: periodicly clean up unused containers
hosts: all
roles:
- role: container_image_cleanup
vars:
podman_prune_cronjob_special_time: daily
docker_prune_cronjob_special_time: weekly
podman_prune_opts: "--all --force"
docker_prune_opts: "--all --force"
podman_path: /usr/bin/podman
docker_path: /usr/bin/docker
```
License
-------
GPLv3
Author Information
------------------
Ilkka Tengvall, ilkka.tengvall@iki.fi

View File

@@ -0,0 +1,10 @@
---
podman_prune_opts: "--all --force"
docker_prune_opts: "--all --force"
podman_path: /usr/bin/podman
docker_path: /usr/bin/docker
podman_prune_cronjob_special_time: daily
docker_prune_cronjob_special_time: daily

View File

@@ -0,0 +1,2 @@
---
# handlers file for container-cleanup

View File

@@ -0,0 +1,2 @@
install_date: Sun Dec 29 00:38:40 2019
version: master

View File

@@ -0,0 +1,19 @@
galaxy_info:
description: Periodicly cleans up all unused container images from host. Role sets up cron job based on whether podman or docker is installed.
author: Ilkka Tengvall
company: ITSE
license: GPLv3
min_ansible_version: 2.4
platforms:
- name: Fedora
versions:
- all
galaxy_tags:
- containers
- podman
- docker
dependencies: []

View File

@@ -0,0 +1,35 @@
---
- name: check if podman is installed
stat:
path: "{{ podman_path }}"
register: podman_binary
- name: mark podman being present
set_fact:
podman_present: present
when: podman_binary.stat.exists
- name: check if docker is installed
stat:
path: "{{ docker_path }}"
register: docker_binary
- name: mark docker being present
set_fact:
docker_present: present
when: docker_binary.stat.exists
- name: ensure periodic task to cleanup unused docker containers
cron:
name: "prune all docker images"
special_time: "{{ docker_prune_cronjob_special_time }}"
job: "{{ docker_path }} image prune {{ docker_prune_opts }} > /dev/null"
state: "{{ docker_present|default('absent') }}"
- name: ensure periodic task to cleanup unused podman containers
cron:
name: "prune all podman images"
special_time: "{{ podman_prune_cronjob_special_time }}"
job: "{{ podman_path }} system prune {{ podman_prune_opts }} > /dev/null"
state: "{{ podman_present|default('absent') }}"

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- container-cleanup

View File

@@ -0,0 +1,2 @@
---
# vars file for container-cleanup