Merge pull request #117 from jpds/cadvisor-role

roles/cadvisor: Added.
This commit is contained in:
Mark Goddard 2018-01-23 15:09:42 +00:00 committed by GitHub
commit 78a1623741
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 166 additions and 0 deletions

14
ansible/cadvisor.yml Normal file
View File

@ -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

View File

@ -0,0 +1,6 @@
---
###############################################################################
# cAdvisor configuration.
# Whether cAdvisor is enabled.
cadvisor_enabled: False

View File

@ -11,3 +11,4 @@
- include: inspection-store.yml
- include: opensm.yml
- include: node-exporter.yml
- include: cadvisor.yml

View File

@ -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 (<jpds@protonmail.com>)

View File

@ -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"
#cadvisor_restart_retries: 10

View File

@ -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 }}"

View File

@ -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] }}"

View File

@ -0,0 +1,2 @@
---
- include: "{{ action }}.yml"

View File

@ -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'

View File

@ -0,0 +1 @@
deploy.yml

View File

@ -0,0 +1,3 @@
---
- include: pull.yml
- include: deploy.yml

10
etc/kayobe/cadvisor.yml Normal file
View File

@ -0,0 +1,10 @@
---
###############################################################################
# cAdvisor configuration.
# Whether cAdvisor is enabled.
#cadvisor_enabled:
###############################################################################
# Dummy variable to allow Ansible to accept this file.
workaround_ansible_issue_8743: yes