Add podman container roles
This commit is contained in:
63
roles/ikke_t.container_image_cleanup/README.md
Normal file
63
roles/ikke_t.container_image_cleanup/README.md
Normal 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
|
||||
10
roles/ikke_t.container_image_cleanup/defaults/main.yml
Normal file
10
roles/ikke_t.container_image_cleanup/defaults/main.yml
Normal 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
|
||||
2
roles/ikke_t.container_image_cleanup/handlers/main.yml
Normal file
2
roles/ikke_t.container_image_cleanup/handlers/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# handlers file for container-cleanup
|
||||
@@ -0,0 +1,2 @@
|
||||
install_date: Sun Dec 29 00:38:40 2019
|
||||
version: master
|
||||
19
roles/ikke_t.container_image_cleanup/meta/main.yml
Normal file
19
roles/ikke_t.container_image_cleanup/meta/main.yml
Normal 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: []
|
||||
35
roles/ikke_t.container_image_cleanup/tasks/main.yml
Normal file
35
roles/ikke_t.container_image_cleanup/tasks/main.yml
Normal 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') }}"
|
||||
2
roles/ikke_t.container_image_cleanup/tests/inventory
Normal file
2
roles/ikke_t.container_image_cleanup/tests/inventory
Normal file
@@ -0,0 +1,2 @@
|
||||
localhost
|
||||
|
||||
5
roles/ikke_t.container_image_cleanup/tests/test.yml
Normal file
5
roles/ikke_t.container_image_cleanup/tests/test.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
---
|
||||
- hosts: localhost
|
||||
remote_user: root
|
||||
roles:
|
||||
- container-cleanup
|
||||
2
roles/ikke_t.container_image_cleanup/vars/main.yml
Normal file
2
roles/ikke_t.container_image_cleanup/vars/main.yml
Normal file
@@ -0,0 +1,2 @@
|
||||
---
|
||||
# vars file for container-cleanup
|
||||
Reference in New Issue
Block a user