Browse Source

consolidate docker service_name and container_name into simply name

Blaine Story 3 years ago
parent
commit
8083e7b432

+ 7 - 14
group_vars/nas.yml

@@ -41,10 +41,9 @@ container_networks:
 # old docker-compose from EPEL complains about mem_limit
 # omit until nas is upgraded
 containers:
-  - service_name: sickchill
+  - name: sickchill
     active: true
     image: linuxserver/sickchill
-    container_name: sickchill
     ports:
       - 8081:8081
     volumes:
@@ -58,10 +57,9 @@ containers:
     networks:
       - downloaders 
 
-  - service_name: transmission
+  - name: transmission
     active: true
     image: linuxserver/transmission
-    container_name: transmission
     ports:
       - 9091:9091
     volumes:
@@ -77,10 +75,9 @@ containers:
     networks:
       - downloaders
 
-  - service_name: qbittorrent
+  - name: qbittorrent
     active: true
     image: linuxserver/qbittorrent
-    container_name: qbittorrent
     ports:
       - 8080:8080
     volumes:
@@ -93,10 +90,9 @@ containers:
     networks:
       - downloaders
 
-  - service_name: heimdall
+  - name: heimdall
     active: true
     image: linuxserver/heimdall
-    container_name: heimdall
     ports:
       - 80:80
     volumes:
@@ -106,10 +102,9 @@ containers:
     networks:
       - heimdall
 
-  - service_name: beets
+  - name: beets
     active: true
     image: linuxserver/beets
-    container_name: beets
     ports:
       - 8337:8337
     volumes:
@@ -119,10 +114,9 @@ containers:
     include_global_env_vars: true
     restart: unless-stopped
 
-  - service_name: gogs
+  - name: gogs
     active: true
     image: gogs/gogs
-    container_name: gogs
     ports:
       - "10022:22" # https://github.com/go-yaml/yaml/issues/34#issuecomment-55772666
       - 10880:3000
@@ -132,10 +126,9 @@ containers:
     networks:
       - heimdall
 
-  - service_name: flask-ytdl
+  - name: flask-ytdl
     active: true
     image: flask-ytdl
-    container_name: flask-ytdl
     ports:
       - 5000:8080
     volumes:

+ 2 - 4
group_vars/shareunderware.yml

@@ -29,10 +29,9 @@ container_networks:
     gateway: 172.21.10.1
 
 containers:
-  - service_name: swag
+  - name: swag
     active: true
     image: linuxserver/swag
-    container_name: swag
     ports:
       - 80:80
       - 443:443
@@ -49,10 +48,9 @@ containers:
     networks:
       - shareunderware
 
-  - service_name: gogs
+  - name: gogs
     active: true
     image: gogs/gogs
-    container_name: gogs
     ports:
       - "10022:22" # https://github.com/go-yaml/yaml/issues/34#issuecomment-55772666
     volumes:

+ 3 - 6
group_vars/warchildstory.yml

@@ -23,10 +23,9 @@ container_networks:
     gateway: 172.28.5.1
 
 containers:
-  - service_name: swag
+  - name: swag
     active: true
     image: linuxserver/swag
-    container_name: swag
     ports:
       - 80:80
       - 443:443
@@ -43,10 +42,9 @@ containers:
     networks:
       - warchildstory
 
-  - service_name: grocy
+  - name: grocy
     active: true
     image: linuxserver/grocy
-    container_name: grocy
     include_global_env_vars: true
     volumes:
       - /opt/grocy:/config
@@ -55,10 +53,9 @@ containers:
       - warchildstory
     mem_limit: 500m
 
-  - service_name: list
+  - name: list
     active: true
     image: linuxserver/nginx
-    container_name: list
     include_global_env_vars: true
     volumes:
       - /opt/list:/config

+ 3 - 6
group_vars/weber.yml

@@ -29,10 +29,9 @@ container_networks:
     gateway: 172.21.0.1
 
 containers:
-  - service_name: sickchill
+  - name: sickchill
     active: true
     image: linuxserver/sickchill
-    container_name: sickchill
     ports:
       - 8081:8081
     volumes:
@@ -45,10 +44,9 @@ containers:
     networks:
       - downloaders
 
-  - service_name: transmission
+  - name: transmission
     active: true
     image: linuxserver/transmission
-    container_name: transmission
     ports:
       - 9091:9091
       - 51413:51413
@@ -64,10 +62,9 @@ containers:
     networks:
       - downloaders
 
-  - service_name: qbittorrent
+  - name: qbittorrent
     active: true
     image: linuxserver/qbittorrent
-    container_name: qbittorrent
     ports:
       - 8080:8080
     volumes:

+ 4 - 4
roles/cloud-backups/templates/backup-to-b2.sh.j2

@@ -9,15 +9,15 @@ LOG_FILE="/var/log/rclone/rclone-$(date +%Y-%m-%d).log"
 {% if container.volumes is defined %}
 {% for volume in container.volumes %}
 {% if backups_ignore not in volume|regex_replace(':.*') %}
-echo "Starting backup of '{{ container.service_name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
-/usr/bin/rclone copy {{ volume | regex_replace(':.*') }}/ b2-container-data:current/{{ ansible_hostname }}/{{ container.service_name }}/{{ volume | regex_replace(':.*') | basename }} \
-      --backup-dir=b2-container-data:old/{{ ansible_hostname }}/{{ container.service_name }}/{{ volume | regex_replace(':.*') | basename }} \
+echo "Starting backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
+/usr/bin/rclone copy {{ volume | regex_replace(':.*') }}/ b2-container-data:current/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
+      --backup-dir=b2-container-data:old/{{ ansible_hostname }}/{{ container.name }}/{{ volume | regex_replace(':.*') | basename }} \
       --suffix=-$(date +%Y-%m-%d) \
       --fast-list \
       --suffix-keep-extension \
       --exclude "*log" \
       --log-file="$LOG_FILE" -v
-echo "Finished backup of '{{ container.service_name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
+echo "Finished backup of '{{ container.name }}:{{ volume | regex_replace(':.*') }}'." | ts >> "$LOG_FILE"
 
 {% endif %}
 {% endfor %}

+ 4 - 4
roles/docker/tasks/main.yml

@@ -44,7 +44,7 @@
     group: root
     mode: '0750'
   with_items:
-    - "{{ containers | map(attribute='service_name') | flatten }}"
+    - "{{ containers | map(attribute='name') | flatten }}"
 
 - name: Create docker networks
   docker_network:
@@ -69,7 +69,7 @@
     group: root
     mode: '0640'
   with_items:
-    - "{{ containers | map(attribute='service_name') | flatten }}"
+    - "{{ containers | map(attribute='name') | flatten }}"
 
 - name: Create container group
   group:
@@ -103,7 +103,7 @@
     mode: '0640'
   notify: Refresh systemd service files
   with_items:
-    - "{{ containers | map(attribute='service_name') | flatten }}"
+    - "{{ containers | map(attribute='name') | flatten }}"
 
 - name: Copy script for automated docker pull
   template:
@@ -156,7 +156,7 @@
     enabled: yes
     state: started
   with_items:
-    - "{{ containers | map(attribute='service_name') | flatten }}"
+    - "{{ containers | map(attribute='name') | flatten }}"
 
 - name: Enable docker timers for automated pull & cleanup
   systemd:

+ 5 - 5
roles/docker/templates/docker-compose.yml.j2

@@ -3,10 +3,10 @@
 version: "{{ compose_schema_version | default('3') }}"
 services:
 {% for container in containers %}
-{% if container.active and container.service_name == item %}
-  {{ container.service_name }}:
+{% if container.active and container.name == item %}
+  {{ container.name }}:
     image: {{ container.image }}
-    container_name: {{ container.container_name | default(container.service_name) }}
+    container_name: {{ container.name }}
 {% if container.extra_hosts is defined %}
     extra_hosts:
 {% for host in container.extra_hosts %}
@@ -105,7 +105,7 @@ services:
     restart: {{ container.restart }}
 {% endif %}
 {% endif %}
-{% if container.networks is defined and container.service_name == item %}
+{% if container.networks is defined and container.name == item %}
     networks:
 {% for network in container.networks %}
       - {{ network }}
@@ -114,7 +114,7 @@ services:
 {% endfor %}
 
 {% for container in containers %}
-{% if container.service_name == item %}
+{% if container.name == item %}
 {% if container.networks is defined %}
 networks:
 {% for network in container.networks %}

+ 1 - 1
roles/docker/templates/docker-pull.sh.j2

@@ -1,7 +1,7 @@
 #!/bin/bash
 # {{ ansible_managed }}
 
-declare -a arr=({{ containers | map(attribute='service_name') | flatten | map('regex_replace', '^(.*)$', '"\\1"') | flatten | join(' ') }})
+declare -a arr=({{ containers | map(attribute='name') | flatten | map('regex_replace', '^(.*)$', '"\\1"') | flatten | join(' ') }})
 
 for i in "${arr[@]}"; do
   output=$(docker-compose -f /root/docker/$i/docker-compose.yml pull)

+ 1 - 1
roles/statusservices/defaults/main.yml

@@ -1,2 +1,2 @@
 ---
-status_services: "{% if containers is defined %}{{ containers | map(attribute='service_name') | flatten | default([]) }}{% else %}[]{% endif %}"
+status_services: "{% if containers is defined %}{{ containers | map(attribute='name') | flatten | default([]) }}{% else %}[]{% endif %}"