From 92cc48330ed171171c6a370644a4778727018fad Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Fri, 18 Sep 2015 12:14:39 -0400 Subject: added playbook for docker storage cleanup --- .../docker_storage_cleanup.yml | 69 ++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml (limited to 'playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml') diff --git a/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml new file mode 100644 index 000000000..1946a5f4f --- /dev/null +++ b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml @@ -0,0 +1,69 @@ +--- +# This playbook attempts to cleanup unwanted docker files to help alleviate docker disk space issues. +# +# To run: +# +# 1. run the playbook: +# +# ansible-playbook -e 'cli_tag_name=' docker_storage_cleanup.yml +# +# Example: +# +# ansible-playbook -e 'cli_tag_name=ops-node-compute-12345' docker_storage_cleanup.yml +# +# Notes: +# * This *should* not interfere with running docker images +# + +- name: Clean up Docker Storage + gather_facts: no + hosts: "tag_Name_{{ cli_tag_name }}" + user: root + connection: ssh + + pre_tasks: + + - fail: + msg: "This playbook requires {{item}} to be set." + when: "{{ item }} is not defined or {{ item }} == ''" + with_items: + - cli_tag_name + + - name: Ensure docker is running + service: + name: docker + state: started + enabled: yes + + - name: Get docker info + command: docker info + register: docker_info + + - name: Show docker info + debug: + var: docker_info.stdout_lines + + - name: Remove exited and dead containers + shell: "docker ps -a | awk '/Exited|Dead/ {print $1}' | xargs --no-run-if-empty docker rm" + ignore_errors: yes + + - name: Remove dangling docker images + shell: "docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi" + ignore_errors: yes + + - name: Remove non-running docker images + shell: "docker images -aq | xargs --no-run-if-empty docker rmi 2>/dev/null" + ignore_errors: yes + + # leaving off the '-t' for docker exec. With it, it doesn't work with ansible and tty support + - name: update zabbix docker items + command: docker exec -i oso-rhel7-zagg-client /usr/local/bin/cron-send-docker-metrics.py + + # Get and show docker info again. + - name: Get docker info + command: docker info + register: docker_info + + - name: Show docker info + debug: + var: docker_info.stdout_lines -- cgit v1.2.3 From d02e346a12c356bd87c0e233d22db03791732841 Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Mon, 21 Sep 2015 10:47:52 -0400 Subject: commented out dangerous playbook option for cleanup --- playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml') diff --git a/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml index 1946a5f4f..53a5c15ef 100644 --- a/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml +++ b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml @@ -51,9 +51,10 @@ shell: "docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi" ignore_errors: yes - - name: Remove non-running docker images - shell: "docker images -aq | xargs --no-run-if-empty docker rmi 2>/dev/null" - ignore_errors: yes +# mwoodson & twiest: this is dangerous, commenting out for now. +# - name: Remove non-running docker images +# shell: "docker images -aq | xargs --no-run-if-empty docker rmi 2>/dev/null" +# ignore_errors: yes # leaving off the '-t' for docker exec. With it, it doesn't work with ansible and tty support - name: update zabbix docker items -- cgit v1.2.3 From 15fef0ed1619709446d7dd0b61d198cc650f53cc Mon Sep 17 00:00:00 2001 From: Matt Woodson Date: Mon, 21 Sep 2015 12:51:56 -0400 Subject: changed the docker cleanup to exclude certain registries --- playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml') diff --git a/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml index 53a5c15ef..a19291a9f 100644 --- a/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml +++ b/playbooks/adhoc/docker_storage_cleanup/docker_storage_cleanup.yml @@ -51,10 +51,9 @@ shell: "docker images -q -f dangling=true | xargs --no-run-if-empty docker rmi" ignore_errors: yes -# mwoodson & twiest: this is dangerous, commenting out for now. -# - name: Remove non-running docker images -# shell: "docker images -aq | xargs --no-run-if-empty docker rmi 2>/dev/null" -# ignore_errors: yes + - name: Remove non-running docker images + shell: "docker images | grep -v -e registry.access.redhat.com -e docker-registry.usersys.redhat.com -e docker-registry.ops.rhcloud.com | awk '{print $3}' | xargs --no-run-if-empty docker rmi 2>/dev/null" + ignore_errors: yes # leaving off the '-t' for docker exec. With it, it doesn't work with ansible and tty support - name: update zabbix docker items -- cgit v1.2.3