From 95b73daa36b23565a8566f71f9b202d3459b685f Mon Sep 17 00:00:00 2001 From: Sam Chudnick Date: Sun, 25 Jun 2023 09:52:36 -0400 Subject: Initial Commit --- .../services/containers/cadvisor/handlers/main.yml | 4 + roles/services/containers/cadvisor/tasks/main.yml | 90 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 roles/services/containers/cadvisor/handlers/main.yml create mode 100644 roles/services/containers/cadvisor/tasks/main.yml (limited to 'roles/services/containers/cadvisor') diff --git a/roles/services/containers/cadvisor/handlers/main.yml b/roles/services/containers/cadvisor/handlers/main.yml new file mode 100644 index 0000000..5463835 --- /dev/null +++ b/roles/services/containers/cadvisor/handlers/main.yml @@ -0,0 +1,4 @@ +- name: restart nginx + service: + name: nginx + state: restarted diff --git a/roles/services/containers/cadvisor/tasks/main.yml b/roles/services/containers/cadvisor/tasks/main.yml new file mode 100644 index 0000000..cc30cdb --- /dev/null +++ b/roles/services/containers/cadvisor/tasks/main.yml @@ -0,0 +1,90 @@ +- name: create cadvisor directory + file: + path: "{{ docker_home }}/cadvisor" + state: directory + owner: "{{ docker_username }}" + group: "{{ docker_username }}" + mode: '0755' + +- name: login to docker registry + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_login: + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + registry_url: "{{ docker_registry_url }}" + username: "{{ docker_registry_username }}" + password: "{{ docker_registry_password }}" + +- name: build cadvisor image + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_image: + name: "{{ docker_registry_url }}/{{ docker_registry_username }}/cadvisor:latest" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + build: + path: /srv/docker/cadvisor/src + dockerfile: deploy/Dockerfile + source: build + push: yes + +- name: create cadvisor docker network + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_network: + name: "{{ cadvisor_network_name }}" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + driver: bridge + ipam_config: + - subnet: "{{ cadvisor_subnet }}" + gateway: "{{ cadvisor_gateway }}" + +- name: create and deploy cadvisor container + become: yes + become_user: "{{ docker_username }}" + environment: + XDG_RUNTIME_DIR: "/run/user/{{ docker_uid }}" + docker_container: + name: "cadvisor" + hostname: "cadvisor" + image: "{{ docker_registry_url }}/{{ docker_registry_username }}/cadvisor:latest" + docker_host: "unix://run/user/{{ docker_uid }}/docker.sock" + purge_networks: yes + networks: + - name: "{{ cadvisor_network_name }}" + ipv4_address: "{{ cadvisor_ipv4 }}" + ports: + - "127.0.0.1:{{ cadvisor_external_port }}:8080" + state: 'started' + comparisons: + '*': strict + restart_policy: unless-stopped + volumes: + - "/:/rootfs:ro" + - "/run/user/{{ docker_uid }}:/var/run:ro" + - "/sys:/sys:ro" + - "/{{ docker_home }}/.local/share/docker:/var/lib/docker:ro" + - "/dev/disk:/dev/disk:ro" + +- name: deploy nginx configuration + notify: restart nginx + register: nginx_config + copy: + src: "{{ cadvisor_nginx_config }}" + dest: /etc/nginx/sites-available/cadvisor.conf + owner: root + group: root + mode: '0644' + +- name: symlink site + file: + src: /etc/nginx/sites-available/cadvisor.conf + dest: /etc/nginx/sites-enabled/cadvisor.conf + owner: root + group: root + state: link -- cgit v1.2.3