From 729a96e6a793a119b6071c7e6d861952817486b5 Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 10:03:51 +0200 Subject: [PATCH 1/9] apt task no longer supports "installed" state --- tasks/apt.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tasks/apt.yml b/tasks/apt.yml index 0393b1a..ea33600 100644 --- a/tasks/apt.yml +++ b/tasks/apt.yml @@ -3,20 +3,20 @@ - name: Ensure apt works with HTTPS and certificates are installed and kernel extrax apt: pkg="{{ item }}" - state="installed" + state="present" update_cache="yes" cache_valid_time=3600 with_items: - apt-transport-https - ca-certificates -- name: Add apt repo GPG +- name: Add apt repo GPG apt_key: id="{{ dockerhost_id }}" url="{{ docker_gpg_url }}" - name: Add docker apt repo - apt_repository: + apt_repository: repo="deb https://download.docker.com/linux/ubuntu {{ ansible_lsb.codename }} stable" update_cache="yes" From 88d69a6814522611fd29927edb4d27cbfe147731 Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 13:03:01 +0200 Subject: [PATCH 2/9] Use newer syntax and fix deprecation warning --- tasks/apt.yml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tasks/apt.yml b/tasks/apt.yml index ea33600..1a79138 100644 --- a/tasks/apt.yml +++ b/tasks/apt.yml @@ -2,13 +2,12 @@ - name: Ensure apt works with HTTPS and certificates are installed and kernel extrax apt: - pkg="{{ item }}" - state="present" - update_cache="yes" - cache_valid_time=3600 - with_items: + pkg: - apt-transport-https - ca-certificates + state: present + update_cache: yes + cache_valid_time: 3600 - name: Add apt repo GPG apt_key: From addd4749482090232daad9fa673335a0cc5638ec Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 13:04:45 +0200 Subject: [PATCH 3/9] Support passing daemon config values --- Readme.md | 1 + defaults/main.yml | 2 ++ tasks/main.yml | 19 +++++++++++++------ templates/daemon.json.j2 | 1 + 4 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 templates/daemon.json.j2 diff --git a/Readme.md b/Readme.md index 789e209..9d1cf49 100644 --- a/Readme.md +++ b/Readme.md @@ -9,6 +9,7 @@ dockerhost_group : "docker" docker_compose_version : "1.25.3" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True +docker_daemon_config : {} ``` ## License diff --git a/defaults/main.yml b/defaults/main.yml index 7c384c6..622b0a1 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -7,3 +7,5 @@ docker_compose_install : True docker_install_py_module : False docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg + +docker_daemon_config : {} diff --git a/tasks/main.yml b/tasks/main.yml index cfe9f15..1a7ae4c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,7 +3,7 @@ #https://docs.docker.com/engine/installation/linux/ubuntulinux/ - name: Add docker group - group: + group: name: "{{ dockerhost_group }}" system: True state: present @@ -24,25 +24,32 @@ when: docker_compose_install - name: Create docker conf - template: + template: src: docker_conf.j2 dest: /etc/default/docker when: ansible_service_mgr != 'systemd' - notify: + notify: - restart docker - name: Create docker systemd unit file - template: + template: src: docker_systemd_service.j2 dest: /etc/systemd/system/docker.service when: ansible_service_mgr == 'systemd' - notify: + notify: + - restart docker systemd + +- name: Create docker daemon config file + template: + src: daemon.json.j2 + dest: /etc/docker/daemon.json + notify: - restart docker systemd - meta: flush_handlers - name: Ensure docker is running and starts by default - service: + service: name: docker state: started enabled: True diff --git a/templates/daemon.json.j2 b/templates/daemon.json.j2 new file mode 100644 index 0000000..57bdc9f --- /dev/null +++ b/templates/daemon.json.j2 @@ -0,0 +1 @@ +{{ docker_daemon_config | to_nice_json }} From ab94c7b7dfc991b78eca4d441be1adfe87e81ded Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 14:28:29 +0200 Subject: [PATCH 4/9] Add cadvisor installation to the role --- Readme.md | 6 ++ defaults/main.yml | 32 +++++++-- handlers/main.yml | 15 +++- meta/main.yml | 6 +- tasks/cadvisor.yml | 75 ++++++++++++++++++++ tasks/main.yml | 4 ++ templates/cadvisor/init.j2 | 107 +++++++++++++++++++++++++++++ templates/cadvisor/systemd-unit.j2 | 15 ++++ templates/cadvisor/upstart.j2 | 16 +++++ vars/main.yml | 2 + 10 files changed, 267 insertions(+), 11 deletions(-) create mode 100644 tasks/cadvisor.yml create mode 100644 templates/cadvisor/init.j2 create mode 100644 templates/cadvisor/systemd-unit.j2 create mode 100644 templates/cadvisor/upstart.j2 diff --git a/Readme.md b/Readme.md index 9d1cf49..d4e8bb9 100644 --- a/Readme.md +++ b/Readme.md @@ -10,6 +10,12 @@ docker_compose_version : "1.25.3" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True docker_daemon_config : {} +install_cadvisor : True +cadvisor_version : "v0.37.5" +cadvisor_config_flags : {} +cadvisor_config_docker_endpoint : unix:///run/docker.sock +cadvisor_config_listen_port : 8100 +cadvisor_config_listen_interface: 0.0.0.0 ``` ## License diff --git a/defaults/main.yml b/defaults/main.yml index 622b0a1..ee3b926 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,11 +1,29 @@ --- -dockerhost_group : "docker" -docker_compose_version : "1.25.3" -docker_compose_dir : "/opt/docker_compose" -docker_compose_install : True -docker_install_py_module : False +dockerhost_group : "docker" +docker_compose_version : "1.25.3" +docker_compose_dir : "/opt/docker_compose" +docker_compose_install : True +docker_install_py_module : False -docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg +docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg -docker_daemon_config : {} +docker_daemon_config : {} + +install_cadvisor : True +prometheus_exporters_common_user : prometheus +prometheus_exporters_common_group : prometheus + +prometheus_exporters_common_root_dir : /opt/prometheus/exporters +prometheus_exporters_common_dist_dir : "{{ prometheus_exporters_common_root_dir }}/dist" +prometheus_exporters_common_conf_dir : "/etc/prometheus/exporters" + +cadvisor_version : v0.37.5 +cadvisor_release_name : "cadvisor-{{ cadvisor_version }}.linux-amd64" +cadvisor_config_flags : {} +cadvisor_config_docker_endpoint : unix:///run/docker.sock +cadvisor_config_listen_port : 8100 +cadvisor_config_listen_interface : 0.0.0.0 + +# Since cAdvisor can potentially replace node exporter, add an option to disable node exporter +disable_prometheus_node_exporter : False diff --git a/handlers/main.yml b/handlers/main.yml index 0b2d6e4..2bb30ae 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,11 +1,22 @@ --- - name: restart docker - service: + service: name: docker state: restarted - name: restart docker systemd - systemd: + systemd: name: docker state: restarted daemon_reload: True + +- name: reenable cadvisor service + command: systemctl reenable cadvisor.service + +- name: reinit cadvisor + command: initctl reload-configuration + +- name: restart cadvisor + service: + name: cadvisor + state: restarted diff --git a/meta/main.yml b/meta/main.yml index 1290db3..7874ce3 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -8,8 +8,10 @@ galaxy_info: platforms: - name: Ubuntu versions: + - 20.04 - 18.04 - 16.04 categories: - - web -dependencies: [] + - web +dependencies: +- UnderGreen.prometheus-exporters-common diff --git a/tasks/cadvisor.yml b/tasks/cadvisor.yml new file mode 100644 index 0000000..9451bf4 --- /dev/null +++ b/tasks/cadvisor.yml @@ -0,0 +1,75 @@ +--- + +- name: Create binary directory + file: + path: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + state: directory + owner: "{{ prometheus_exporters_common_user }}" + group: "{{ prometheus_exporters_common_group }}" + +- name: download cadvisor binary + get_url: + url: "{{ cadvisor_download_url }}" + dest: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}/cadvisor" + mode: "0755" + +- name: create symlink to the current release + file: + src: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + path: "{{ prometheus_exporters_common_root_dir }}/cadvisor_current" + state: link + +- name: create systemd service unit + template: + src: cadvisor/systemd-unit.j2 + dest: /etc/systemd/system/cadvisor.service + owner: root + group: root + mode: 0644 + when: ansible_service_mgr == 'systemd' + notify: + - reenable cadvisor service + - restart cadvisor + +- name: get upstart version + command: initctl version + when: ansible_service_mgr == 'upstart' + register: upstart_version + +- name: create init service unit + template: + src: cadvisor/upstart.j2 + dest: /etc/init/cadvisor.conf + owner: root + group: root + mode: 0644 + when: ansible_service_mgr == 'upstart' + notify: + - reinit cadvisor + - restart cadvisor + +- name: create sysvinit service unit + template: + src: cadvisor/init.j2 + dest: /etc/init.d/cadvisor + owner: root + group: root + mode: 0755 + when: ansible_service_mgr == 'sysvinit' + notify: + - restart cadvisor + +- name: disable node exporter service + when: disable_prometheus_node_exporter|bool + service: + name: prometheus-node-exporter + state: stopped + enabled: no + +- meta: flush_handlers + +- name: ensure cadvisor is running + service: + name: cadvisor + enabled: yes + state: started diff --git a/tasks/main.yml b/tasks/main.yml index 1a7ae4c..e5831c9 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -53,3 +53,7 @@ name: docker state: started enabled: True + +- name: Include cadvisor + include: cadvisor.yml + when: install_cadvisor diff --git a/templates/cadvisor/init.j2 b/templates/cadvisor/init.j2 new file mode 100644 index 0000000..c675fa5 --- /dev/null +++ b/templates/cadvisor/init.j2 @@ -0,0 +1,107 @@ +#!/bin/sh +# +# +# +# chkconfig: 345 99 01 +# description: Manage service cadvisor + + +### BEGIN INIT INFO +# Provides: cadvisor +# Required-Start: +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: +# Default-Stop: +# Short-Description: +# Description: Manage service cadvisor +### END INIT INFO + +# Source function library. +. /etc/rc.d/init.d/functions + +exec="/opt/prometheus/exporters/cadvisor_current/cadvisor" +prog="cadvisor" +# cadvisor is not able to manage configuration file +#config="" + +[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog + +lockfile=/var/lock/subsys/$prog + +start() { + [ -x $exec ] || exit 5 + #[ -f $config ] || exit 6 + echo -n $"Starting $prog: " + # if not running, start it up here, usually something like "daemon $exec" + daemon {{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} + echo + [ $retval -eq 0 ] && touch $lockfile + return $retval +} + +stop() { + echo -n $"Stopping $prog: " + # stop it here, often "killproc $prog" + killproc /opt/prometheus/exporters/cadvisor_current/cadvisor + retval=$? + echo + [ $retval -eq 0 ] && rm -f $lockfile + return $retval +} + +restart() { + stop + start +} + +reload() { + restart +} + +force_reload() { + restart +} + +rh_status() { + # run checks to determine if the service is running or use generic status + status $prog +} + +rh_status_q() { + rh_status >/dev/null 2>&1 +} + + +case "$1" in + start) + rh_status_q && exit 0 + $1 + ;; + stop) + rh_status_q || exit 0 + $1 + ;; + restart) + $1 + ;; + reload) + rh_status_q || exit 7 + $1 + ;; + force-reload) + force_reload + ;; + status) + rh_status + ;; + condrestart|try-restart) + rh_status_q || exit 0 + restart + ;; + *) + echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" + exit 2 +esac +exit $? diff --git a/templates/cadvisor/systemd-unit.j2 b/templates/cadvisor/systemd-unit.j2 new file mode 100644 index 0000000..b4bce9a --- /dev/null +++ b/templates/cadvisor/systemd-unit.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=cadvisor +After=network.target + +[Service] +Type=simple +User=root +Group=root +ExecStart={{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} + +SyslogIdentifier=cadvisor +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/templates/cadvisor/upstart.j2 b/templates/cadvisor/upstart.j2 new file mode 100644 index 0000000..20a2700 --- /dev/null +++ b/templates/cadvisor/upstart.j2 @@ -0,0 +1,16 @@ +description "cadvisor" +start on (local-filesystems and net-device-up IFACE!=lo) +stop on runlevel [016] + +respawn +{% if upstart_version.stdout | replace("init (upstart ", "") |replace(")","") | version_compare('1.4', '>=') %} +setuid root +setgid root +{% endif %} + +script + exec >> "{{ prometheus_exporters_common_log_dir }}/cadvisor.log" + exec 2>&1 + exec {{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} + +end script diff --git a/vars/main.yml b/vars/main.yml index e5665b6..3975191 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -5,3 +5,5 @@ dockerhost_id : "7EA0A9C3F273FCD8" docker_compose_file : "docker-compose-Linux-{{ ansible_userspace_architecture }}-{{ docker_compose_version }}" docker_compose_url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-{{ ansible_userspace_architecture }}" + +cadvisor_download_url : "https://github.com/google/cadvisor/releases/download/{{ cadvisor_version }}/cadvisor" From 18b17e9cf48df79fe5a0bf3f768511e16ffcbe3e Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 14:58:35 +0200 Subject: [PATCH 5/9] Use latest version of docker-compose --- Readme.md | 2 +- defaults/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index d4e8bb9..eb5f117 100644 --- a/Readme.md +++ b/Readme.md @@ -6,7 +6,7 @@ An ansible role that installs docker host on ubuntu ### Role Variables ```yaml dockerhost_group : "docker" -docker_compose_version : "1.25.3" +docker_compose_version : "1.29.1" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True docker_daemon_config : {} diff --git a/defaults/main.yml b/defaults/main.yml index ee3b926..a0dd091 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,7 +1,7 @@ --- dockerhost_group : "docker" -docker_compose_version : "1.25.3" +docker_compose_version : "1.29.1" docker_compose_dir : "/opt/docker_compose" docker_compose_install : True docker_install_py_module : False From 26ee8856eabcb74535b380e9c76889499dab34c4 Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 15:46:51 +0200 Subject: [PATCH 6/9] Prefix new variables with role name Rename new variables to have the role name as prefix --- Readme.md | 22 ++++++++-------- defaults/main.yml | 40 +++++++++++++++--------------- tasks/cadvisor.yml | 14 +++++------ tasks/main.yml | 2 +- templates/cadvisor/init.j2 | 16 ++++++------ templates/cadvisor/systemd-unit.j2 | 2 +- templates/cadvisor/upstart.j2 | 2 +- templates/daemon.json.j2 | 2 +- vars/main.yml | 2 +- 9 files changed, 51 insertions(+), 51 deletions(-) diff --git a/Readme.md b/Readme.md index eb5f117..245a408 100644 --- a/Readme.md +++ b/Readme.md @@ -5,17 +5,17 @@ An ansible role that installs docker host on ubuntu ### Role Variables ```yaml -dockerhost_group : "docker" -docker_compose_version : "1.29.1" -docker_compose_dir : "/opt/docker_compose" -docker_compose_install : True -docker_daemon_config : {} -install_cadvisor : True -cadvisor_version : "v0.37.5" -cadvisor_config_flags : {} -cadvisor_config_docker_endpoint : unix:///run/docker.sock -cadvisor_config_listen_port : 8100 -cadvisor_config_listen_interface: 0.0.0.0 +dockerhost_group : "docker" +docker_compose_version : "1.29.1" +docker_compose_dir : "/opt/docker_compose" +docker_compose_install : True +dockerhost_daemon_config : {} +dockerhost_install_cadvisor : True +dockerhost_cadvisor_version : "v0.37.5" +dockerhost_cadvisor_config_flags : {} +dockerhost_cadvisor_config_docker_endpoint : unix:///run/docker.sock +dockerhost_cadvisor_config_listen_port : 8100 +dockerhost_cadvisor_config_listen_interface : 0.0.0.0 ``` ## License diff --git a/defaults/main.yml b/defaults/main.yml index a0dd091..db24f98 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,29 +1,29 @@ --- -dockerhost_group : "docker" -docker_compose_version : "1.29.1" -docker_compose_dir : "/opt/docker_compose" -docker_compose_install : True -docker_install_py_module : False +dockerhost_group : "docker" +docker_compose_version : "1.29.1" +docker_compose_dir : "/opt/docker_compose" +docker_compose_install : True +docker_install_py_module : False -docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg +docker_gpg_url : https://download.docker.com/linux/ubuntu/gpg -docker_daemon_config : {} +dockerhost_daemon_config : {} -install_cadvisor : True -prometheus_exporters_common_user : prometheus -prometheus_exporters_common_group : prometheus +dockerhost_install_cadvisor : True +dockerhost_prometheus_exporters_common_user : prometheus +dockerhost_prometheus_exporters_common_group : prometheus -prometheus_exporters_common_root_dir : /opt/prometheus/exporters -prometheus_exporters_common_dist_dir : "{{ prometheus_exporters_common_root_dir }}/dist" -prometheus_exporters_common_conf_dir : "/etc/prometheus/exporters" +dockerhost_prometheus_exporters_common_root_dir : /opt/prometheus/exporters +dockerhost_prometheus_exporters_common_dist_dir : "{{ dockerhost_prometheus_exporters_common_root_dir }}/dist" +dockerhost_prometheus_exporters_common_conf_dir : "/etc/prometheus/exporters" -cadvisor_version : v0.37.5 -cadvisor_release_name : "cadvisor-{{ cadvisor_version }}.linux-amd64" -cadvisor_config_flags : {} -cadvisor_config_docker_endpoint : unix:///run/docker.sock -cadvisor_config_listen_port : 8100 -cadvisor_config_listen_interface : 0.0.0.0 +dockerhost_cadvisor_version : v0.37.5 +cadvisor_release_name : "cadvisor-{{ dockerhost_cadvisor_version }}.linux-amd64" +dockerhost_cadvisor_config_flags : {} +dockerhost_cadvisor_config_docker_endpoint : unix:///run/docker.sock +dockerhost_cadvisor_config_listen_port : 8100 +dockerhost_cadvisor_config_listen_interface : 0.0.0.0 # Since cAdvisor can potentially replace node exporter, add an option to disable node exporter -disable_prometheus_node_exporter : False +dockerhost_disable_prometheus_node_exporter : False diff --git a/tasks/cadvisor.yml b/tasks/cadvisor.yml index 9451bf4..4b3bc07 100644 --- a/tasks/cadvisor.yml +++ b/tasks/cadvisor.yml @@ -2,21 +2,21 @@ - name: Create binary directory file: - path: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + path: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" state: directory - owner: "{{ prometheus_exporters_common_user }}" - group: "{{ prometheus_exporters_common_group }}" + owner: "{{ dockerhost_prometheus_exporters_common_user }}" + group: "{{ dockerhost_prometheus_exporters_common_group }}" - name: download cadvisor binary get_url: url: "{{ cadvisor_download_url }}" - dest: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}/cadvisor" + dest: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}/cadvisor" mode: "0755" - name: create symlink to the current release file: - src: "{{ prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" - path: "{{ prometheus_exporters_common_root_dir }}/cadvisor_current" + src: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + path: "{{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current" state: link - name: create systemd service unit @@ -60,7 +60,7 @@ - restart cadvisor - name: disable node exporter service - when: disable_prometheus_node_exporter|bool + when: dockerhost_disable_prometheus_node_exporter|bool service: name: prometheus-node-exporter state: stopped diff --git a/tasks/main.yml b/tasks/main.yml index e5831c9..e946b0a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -56,4 +56,4 @@ - name: Include cadvisor include: cadvisor.yml - when: install_cadvisor + when: dockerhost_install_cadvisor diff --git a/templates/cadvisor/init.j2 b/templates/cadvisor/init.j2 index c675fa5..88cf9d0 100644 --- a/templates/cadvisor/init.j2 +++ b/templates/cadvisor/init.j2 @@ -8,13 +8,13 @@ ### BEGIN INIT INFO # Provides: cadvisor -# Required-Start: -# Required-Stop: -# Should-Start: -# Should-Stop: -# Default-Start: -# Default-Stop: -# Short-Description: +# Required-Start: +# Required-Stop: +# Should-Start: +# Should-Stop: +# Default-Start: +# Default-Stop: +# Short-Description: # Description: Manage service cadvisor ### END INIT INFO @@ -35,7 +35,7 @@ start() { #[ -f $config ] || exit 6 echo -n $"Starting $prog: " # if not running, start it up here, usually something like "daemon $exec" - daemon {{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} + daemon {{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} echo [ $retval -eq 0 ] && touch $lockfile return $retval diff --git a/templates/cadvisor/systemd-unit.j2 b/templates/cadvisor/systemd-unit.j2 index b4bce9a..d3de55e 100644 --- a/templates/cadvisor/systemd-unit.j2 +++ b/templates/cadvisor/systemd-unit.j2 @@ -6,7 +6,7 @@ After=network.target Type=simple User=root Group=root -ExecStart={{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} +ExecStart={{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} SyslogIdentifier=cadvisor Restart=always diff --git a/templates/cadvisor/upstart.j2 b/templates/cadvisor/upstart.j2 index 20a2700..17af284 100644 --- a/templates/cadvisor/upstart.j2 +++ b/templates/cadvisor/upstart.j2 @@ -11,6 +11,6 @@ setgid root script exec >> "{{ prometheus_exporters_common_log_dir }}/cadvisor.log" exec 2>&1 - exec {{ prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ cadvisor_config_docker_endpoint }}" --listen_ip="{{ cadvisor_config_listen_interface }}" --port="{{ cadvisor_config_listen_port }}" {% for flag, flag_value in cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} + exec {{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %} end script diff --git a/templates/daemon.json.j2 b/templates/daemon.json.j2 index 57bdc9f..63ba48d 100644 --- a/templates/daemon.json.j2 +++ b/templates/daemon.json.j2 @@ -1 +1 @@ -{{ docker_daemon_config | to_nice_json }} +{{ dockerhost_daemon_config | to_nice_json }} diff --git a/vars/main.yml b/vars/main.yml index 3975191..5e6e23f 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -6,4 +6,4 @@ dockerhost_id : "7EA0A9C3F273FCD8" docker_compose_file : "docker-compose-Linux-{{ ansible_userspace_architecture }}-{{ docker_compose_version }}" docker_compose_url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-{{ ansible_userspace_architecture }}" -cadvisor_download_url : "https://github.com/google/cadvisor/releases/download/{{ cadvisor_version }}/cadvisor" +cadvisor_download_url : "https://github.com/google/cadvisor/releases/download/{{ dockerhost_cadvisor_version }}/cadvisor" From 189e12fc4fe07092b769616cd08e46d67b87bc5e Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 16:10:07 +0200 Subject: [PATCH 7/9] Renamed one more variable Missed it in the last rename sweep --- defaults/main.yml | 2 +- tasks/cadvisor.yml | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/defaults/main.yml b/defaults/main.yml index db24f98..cca2006 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -19,7 +19,7 @@ dockerhost_prometheus_exporters_common_dist_dir : "{{ dockerhost_prometheus_expo dockerhost_prometheus_exporters_common_conf_dir : "/etc/prometheus/exporters" dockerhost_cadvisor_version : v0.37.5 -cadvisor_release_name : "cadvisor-{{ dockerhost_cadvisor_version }}.linux-amd64" +dockerhost_cadvisor_release_name : "cadvisor-{{ dockerhost_cadvisor_version }}.linux-amd64" dockerhost_cadvisor_config_flags : {} dockerhost_cadvisor_config_docker_endpoint : unix:///run/docker.sock dockerhost_cadvisor_config_listen_port : 8100 diff --git a/tasks/cadvisor.yml b/tasks/cadvisor.yml index 4b3bc07..00e1526 100644 --- a/tasks/cadvisor.yml +++ b/tasks/cadvisor.yml @@ -2,7 +2,7 @@ - name: Create binary directory file: - path: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + path: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}" state: directory owner: "{{ dockerhost_prometheus_exporters_common_user }}" group: "{{ dockerhost_prometheus_exporters_common_group }}" @@ -10,12 +10,12 @@ - name: download cadvisor binary get_url: url: "{{ cadvisor_download_url }}" - dest: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}/cadvisor" + dest: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}/cadvisor" mode: "0755" - name: create symlink to the current release file: - src: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ cadvisor_release_name }}" + src: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}" path: "{{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current" state: link From 234676721c6dd98d9ade8483b316d93a65e63ca2 Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 16:12:20 +0200 Subject: [PATCH 8/9] Renamed cadvisor_download_url variable --- tasks/cadvisor.yml | 2 +- vars/main.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tasks/cadvisor.yml b/tasks/cadvisor.yml index 00e1526..a57a8cc 100644 --- a/tasks/cadvisor.yml +++ b/tasks/cadvisor.yml @@ -9,7 +9,7 @@ - name: download cadvisor binary get_url: - url: "{{ cadvisor_download_url }}" + url: "{{ dockerhost_cadvisor_download_url }}" dest: "{{ dockerhost_prometheus_exporters_common_dist_dir }}/{{ dockerhost_cadvisor_release_name }}/cadvisor" mode: "0755" diff --git a/vars/main.yml b/vars/main.yml index 5e6e23f..4193219 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -6,4 +6,4 @@ dockerhost_id : "7EA0A9C3F273FCD8" docker_compose_file : "docker-compose-Linux-{{ ansible_userspace_architecture }}-{{ docker_compose_version }}" docker_compose_url : "https://github.com/docker/compose/releases/download/{{ docker_compose_version }}/docker-compose-Linux-{{ ansible_userspace_architecture }}" -cadvisor_download_url : "https://github.com/google/cadvisor/releases/download/{{ dockerhost_cadvisor_version }}/cadvisor" +dockerhost_cadvisor_download_url : "https://github.com/google/cadvisor/releases/download/{{ dockerhost_cadvisor_version }}/cadvisor" From 4dd878aae969b38b824d77557330ddb6ee2dd4c0 Mon Sep 17 00:00:00 2001 From: Josiah Adenegan Date: Wed, 12 May 2021 16:14:19 +0200 Subject: [PATCH 9/9] Renamed prometheus_exporters_common_log_dir --- templates/cadvisor/upstart.j2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cadvisor/upstart.j2 b/templates/cadvisor/upstart.j2 index 17af284..1df1b1c 100644 --- a/templates/cadvisor/upstart.j2 +++ b/templates/cadvisor/upstart.j2 @@ -9,7 +9,7 @@ setgid root {% endif %} script - exec >> "{{ prometheus_exporters_common_log_dir }}/cadvisor.log" + exec >> "{{ dockerhost_prometheus_exporters_common_log_dir }}/cadvisor.log" exec 2>&1 exec {{ dockerhost_prometheus_exporters_common_root_dir }}/cadvisor_current/cadvisor --docker="{{ dockerhost_cadvisor_config_docker_endpoint }}" --listen_ip="{{ dockerhost_cadvisor_config_listen_interface }}" --port="{{ dockerhost_cadvisor_config_listen_port }}" {% for flag, flag_value in dockerhost_cadvisor_config_flags.items() %}--{{ flag }}={{ flag_value }} {% endfor %}