roles/cadvisor: Added.
This commit is contained in:
parent
31befe5340
commit
6277688be9
14
ansible/cadvisor.yml
Normal file
14
ansible/cadvisor.yml
Normal 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
|
@ -11,3 +11,4 @@
|
|||||||
- include: inspection-store.yml
|
- include: inspection-store.yml
|
||||||
- include: opensm.yml
|
- include: opensm.yml
|
||||||
- include: node-exporter.yml
|
- include: node-exporter.yml
|
||||||
|
- include: cadvisor.yml
|
||||||
|
44
ansible/roles/cadvisor/README.md
Normal file
44
ansible/roles/cadvisor/README.md
Normal 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>)
|
31
ansible/roles/cadvisor/defaults/main.yml
Normal file
31
ansible/roles/cadvisor/defaults/main.yml
Normal 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"
|
||||||
|
#nodeexporter_restart_retries: 10
|
15
ansible/roles/cadvisor/tasks/deploy.yml
Normal file
15
ansible/roles/cadvisor/tasks/deploy.yml
Normal 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 }}"
|
29
ansible/roles/cadvisor/tasks/destroy.yml
Normal file
29
ansible/roles/cadvisor/tasks/destroy.yml
Normal 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] }}"
|
2
ansible/roles/cadvisor/tasks/main.yml
Normal file
2
ansible/roles/cadvisor/tasks/main.yml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
- include: "{{ action }}.yml"
|
10
ansible/roles/cadvisor/tasks/pull.yml
Normal file
10
ansible/roles/cadvisor/tasks/pull.yml
Normal 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'
|
1
ansible/roles/cadvisor/tasks/reconfigure.yml
Symbolic link
1
ansible/roles/cadvisor/tasks/reconfigure.yml
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
deploy.yml
|
3
ansible/roles/cadvisor/tasks/upgrade.yml
Normal file
3
ansible/roles/cadvisor/tasks/upgrade.yml
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
---
|
||||||
|
- include: pull.yml
|
||||||
|
- include: deploy.yml
|
Loading…
Reference in New Issue
Block a user