From 6277688be9278d1df1f60eb6cf0c22538ef7cbb1 Mon Sep 17 00:00:00 2001 From: Jonathan Davies Date: Tue, 23 Jan 2018 12:17:17 +0000 Subject: [PATCH] roles/cadvisor: Added. --- ansible/cadvisor.yml | 14 +++++++ ansible/overcloud-extras.yml | 1 + ansible/roles/cadvisor/README.md | 44 ++++++++++++++++++++ ansible/roles/cadvisor/defaults/main.yml | 31 ++++++++++++++ ansible/roles/cadvisor/tasks/deploy.yml | 15 +++++++ ansible/roles/cadvisor/tasks/destroy.yml | 29 +++++++++++++ ansible/roles/cadvisor/tasks/main.yml | 2 + ansible/roles/cadvisor/tasks/pull.yml | 10 +++++ ansible/roles/cadvisor/tasks/reconfigure.yml | 1 + ansible/roles/cadvisor/tasks/upgrade.yml | 3 ++ 10 files changed, 150 insertions(+) create mode 100644 ansible/cadvisor.yml create mode 100644 ansible/roles/cadvisor/README.md create mode 100644 ansible/roles/cadvisor/defaults/main.yml create mode 100644 ansible/roles/cadvisor/tasks/deploy.yml create mode 100644 ansible/roles/cadvisor/tasks/destroy.yml create mode 100644 ansible/roles/cadvisor/tasks/main.yml create mode 100644 ansible/roles/cadvisor/tasks/pull.yml create mode 120000 ansible/roles/cadvisor/tasks/reconfigure.yml create mode 100644 ansible/roles/cadvisor/tasks/upgrade.yml diff --git a/ansible/cadvisor.yml b/ansible/cadvisor.yml new file mode 100644 index 000000000..97a51d211 --- /dev/null +++ b/ansible/cadvisor.yml @@ -0,0 +1,14 @@ +--- +# Deploy/pull/reconfigure/upgrade cAdvisor. +# +# Follows kolla-ansible service deployment patterns. +# +# Variables: +# action: One of deploy, destroy, pull, reconfigure, upgrade + +- name: Ensure cAdvisor is deployed + hosts: overcloud:&docker + tags: + - cadvisor + roles: + - role: cadvisor diff --git a/ansible/overcloud-extras.yml b/ansible/overcloud-extras.yml index 58aec6f70..453abae5b 100644 --- a/ansible/overcloud-extras.yml +++ b/ansible/overcloud-extras.yml @@ -11,3 +11,4 @@ - include: inspection-store.yml - include: opensm.yml - include: node-exporter.yml +- include: cadvisor.yml diff --git a/ansible/roles/cadvisor/README.md b/ansible/roles/cadvisor/README.md new file mode 100644 index 000000000..a9e9feb36 --- /dev/null +++ b/ansible/roles/cadvisor/README.md @@ -0,0 +1,44 @@ +cAdvisor +======== + +This role can be used to configure cAdvisor running in a Docker container. + +Requirements +------------ + +The host executing the role has the following requirements: + +* Docker engine +* Python ``docker >= 2.0.0`` + +Role Variables +-------------- + +``cadvisor_enabled``: Whether the cAdvisor is enabled. Defaults to ``false``. +``cadvisor_namespace``: Docker image namespace. Defaults to ``cadvisor``. +``cadvisor_image``: Docker image name. +``cadvisor_tag``: Docker image tag. Defaults to ``v0.28.3``. +``cadvisor_image_full``: Full docker image specification. +``cadvisor_restart_policy``: Docker restart policy for cAdvisor container. Defaults +to ``unless-stopped``. +``cadvisor_restart_retries``: Number of Docker restarts. Defaults to 10. + +Dependencies +------------ + +None + +Example Playbook +---------------- + +The following playbook configures cAdvisor. + + --- + - hosts: cadvisor + roles: + - role: cadvisor + +Author Information +------------------ + +- Jonathan Davies () diff --git a/ansible/roles/cadvisor/defaults/main.yml b/ansible/roles/cadvisor/defaults/main.yml new file mode 100644 index 000000000..c347a76e4 --- /dev/null +++ b/ansible/roles/cadvisor/defaults/main.yml @@ -0,0 +1,31 @@ +--- +# Roughly follows kolla-ansible's service deployment patterns. + +# Whether cAdvisor is enabled. +cadvisor_enabled: false + +# Service deployment definition. +cadvisor_services: + cadvisor: + container_name: cadvisor + enabled: "{{ cadvisor_enabled }}" + image: "{{ cadvisor_image_full }}" + published_ports: '8080:8080' + read_only: True + volumes: + - "/:/rootfs" + - "/var/run:/var/run:rw" + - "/sys:/sys:ro" + - "/var/lib/docker/:/var/lib/docker:ro" + - "/dev/disk/:/dev/disk:ro" + +#################### +# Docker +#################### +cadvisor_namespace: "cadvisor" +cadvisor_image: "{{ docker_registry ~ '/' if docker_registry | default else '' }}{{ cadvisor_namespace }}/cadvisor" +cadvisor_tag: "v0.28.3" +cadvisor_image_full: "{{ cadvisor_image }}:{{ cadvisor_tag }}" + +cadvisor_restart_policy: "unless-stopped" +#nodeexporter_restart_retries: 10 diff --git a/ansible/roles/cadvisor/tasks/deploy.yml b/ansible/roles/cadvisor/tasks/deploy.yml new file mode 100644 index 000000000..0a2242f52 --- /dev/null +++ b/ansible/roles/cadvisor/tasks/deploy.yml @@ -0,0 +1,15 @@ +--- +- name: Ensure cAdvisor container is running + docker_container: + image: "{{ item.value.image }}" + name: "{{ item.value.container_name }}" + command: "{{ item.value.command }}" + network_mode: "host" + privileged: "{{ item.value.privileged | default(omit) }}" + published_ports: "{{ item.value.published_ports | default(omit) }}" + read_only: "{{ item.value.read_only | default(omit) }}" + restart_policy: "{{ nodeexporter_restart_policy }}" + restart_retries: "{{ nodeexporter_restart_retries | default(omit) }}" + state: "{{ item.value.enabled | ternary('started', 'absent') }}" + volumes: "{{ item.value.volumes }}" + with_dict: "{{ cadvisor_services }}" diff --git a/ansible/roles/cadvisor/tasks/destroy.yml b/ansible/roles/cadvisor/tasks/destroy.yml new file mode 100644 index 000000000..7b937212e --- /dev/null +++ b/ansible/roles/cadvisor/tasks/destroy.yml @@ -0,0 +1,29 @@ +--- +- name: Ensure cAdvisor container is stopped + docker_container: + name: "{{ item.value.container_name }}" + state: "absent" + with_dict: "{{ cadvisor_services }}" + +- name: Check whether cAdvisor volumes are present + command: docker volume inspect {{ volume }} + changed_when: False + with_subelements: + - "{{ cadvisor_services }}" + - volumes + when: "'/' not in volume" + failed_when: + - volume_result.rc != 0 + - "'No such volume' not in volume_result.stderr" + vars: + volume: "{{ item.1.split(':')[0] }}" + register: volume_result + +- name: Ensure cAdvisor volumes are absent + command: docker volume rm {{ volume }} + with_items: "{{ volume_result.results }}" + when: + - not item | skipped + - item.rc == 0 + vars: + volume: "{{ item.item.1.split(':')[0] }}" diff --git a/ansible/roles/cadvisor/tasks/main.yml b/ansible/roles/cadvisor/tasks/main.yml new file mode 100644 index 000000000..b017e8b4a --- /dev/null +++ b/ansible/roles/cadvisor/tasks/main.yml @@ -0,0 +1,2 @@ +--- +- include: "{{ action }}.yml" diff --git a/ansible/roles/cadvisor/tasks/pull.yml b/ansible/roles/cadvisor/tasks/pull.yml new file mode 100644 index 000000000..5800ef342 --- /dev/null +++ b/ansible/roles/cadvisor/tasks/pull.yml @@ -0,0 +1,10 @@ +--- +- name: Pulling cAdvisor container image + docker_image: + name: "{{ item.value.image }}" + repository: "{{ item.value.image }}" + state: present + with_dict: "{{ cadvisor_services }}" + when: + - item.value.enabled + - action != 'destroy' diff --git a/ansible/roles/cadvisor/tasks/reconfigure.yml b/ansible/roles/cadvisor/tasks/reconfigure.yml new file mode 120000 index 000000000..0412f9220 --- /dev/null +++ b/ansible/roles/cadvisor/tasks/reconfigure.yml @@ -0,0 +1 @@ +deploy.yml \ No newline at end of file diff --git a/ansible/roles/cadvisor/tasks/upgrade.yml b/ansible/roles/cadvisor/tasks/upgrade.yml new file mode 100644 index 000000000..8459b03ca --- /dev/null +++ b/ansible/roles/cadvisor/tasks/upgrade.yml @@ -0,0 +1,3 @@ +--- +- include: pull.yml +- include: deploy.yml