Registry updated to v3 and from nginx to caddy

This commit is contained in:
tanshu committed 2025-07-30 04:17:32 +00:00
1 parent e429ce661e
commit dc2e11ca69
10 files changed
+83 -72

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
---
# Handlers for Nginx role
- name: Restart caddy container
docker_container:
name: "{{ caddy_container }}"
state: started
restart: true
+22
View File
@@ -0,0 +1,22 @@
---
- name: Read current Caddyfile
ansible.builtin.slurp:
path: "{{ caddyfile_path }}"
register: caddyfile_raw
- name: Decode Caddyfile content
set_fact:
caddyfile_content: "{{ caddyfile_raw['content'] | b64decode }}"
- name: Check if snippet already exists
set_fact:
snippet_present: "{{ snippet_block in caddyfile_content }}"
- name: Add snippet if missing
ansible.builtin.blockinfile:
path: "{{ caddyfile_path }}"
marker: "# {mark} Ansible managed Caddy snippet for {{ host }}"
block: "{{ snippet_block }}"
create: yes
when: not snippet_present
notify: Restart caddy container
+8
View File
@@ -0,0 +1,8 @@
---
- name: "Ensure {{ docker_container }} Docker network exists"
docker_network:
name: "{{ docker_network }}"
state: present
connected:
- "{{ caddy_container }}"
appends: yes
-6
View File
@@ -1,6 +0,0 @@
---
# Handlers for Nginx role
- name: Reload Nginx
service:
name: nginx
state: reloaded
-24
View File
@@ -1,24 +0,0 @@
---
# Tasks for Nginx role
- name: Check if Nginx conf file exists
stat:
path: "/etc/nginx/sites-available/{{ http_conf }}"
register: status
- name: No need to reload Nginx
debug:
msg: "No need to reload Nginx as sites-available entries have already been created"
- name: Set Nginx conf file
when: status.stat.exists == false
template:
src: "files/nginx.conf.j2"
dest: "/etc/nginx/sites-available/{{ http_conf }}"
- name: Enable new site
when: status.stat.exists == false
file:
src: "/etc/nginx/sites-available/{{ http_conf }}"
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
state: link
notify: Reload Nginx
+14 -8
View File
@@ -18,12 +18,23 @@
state: directory
mode: 0755
- name: Upload config.yml for Registry
template:
src: "files/config.yml"
dest: "/var/lib/{{ host_directory }}/config.yml"
- name: Make sure that apache2-utils is installed for htpasswd
ansible.builtin.package:
name: apache2-utils
state: present
- name: Check if htpasswd file exists
stat:
path: "/var/lib/{{ host_directory }}/auth/registry.passwd"
register: htpasswdstatus
- name: Create htpasswd file with user and password
when: htpasswdstatus.stat.exists == false
expect:
command: "htpasswd -Bc /var/lib/{{ host_directory }}/auth/registry.passwd {{ username }}"
responses:
@@ -31,20 +42,15 @@
(?i)Re-type new password: "{{ password }}"
# no_log: true
- name: Create registry container
docker_container:
name: "{{ docker_container }}"
image: "{{ docker_image }}"
state: started
restart_policy: "unless-stopped"
env:
REGISTRY_AUTH: htpasswd
REGISTRY_AUTH_HTPASSWD_REALM: Registry
REGISTRY_AUTH_HTPASSWD_PATH: /auth/registry.passwd
REGISTRY_STORAGE_FILESYSTEM_ROOTDIRECTORY: /data
published_ports:
- "127.0.0.1:{{ host_port }}:5000"
volumes:
- "/var/lib/{{ host_directory }}/data:/data"
- "/var/lib/{{ host_directory }}/auth:/auth"
- "/var/lib/{{ host_directory }}/config.yml:/etc/docker/registry/config.yml"
networks:
- name: "{{ docker_network }}"