Docker registry

This commit is contained in:
tanshu committed 2024-12-17 17:53:30 +05:30
1 parent 2f767a1826
commit f04a29b5c7
7 files changed
+131

No files matched your search

+6
View File
@@ -0,0 +1,6 @@
---
# Handlers for Nginx role
- name: Reload Nginx
service:
name: nginx
state: reloaded
+24
View File
@@ -0,0 +1,24 @@
---
# 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
+50
View File
@@ -0,0 +1,50 @@
---
# Tasks for a Private Docker registry role
- name: Pull Registry image
docker_image:
name: "{{ docker_image }}"
source: pull
force_source: yes
- name: Ensure Registry Directory exists
file:
path: "/var/lib/{{ host_directory }}"
state: directory
mode: 0755
- name: Ensure Registry Auth Directory exists
file:
path: "/var/lib/{{ host_directory }}/auth"
state: directory
mode: 0755
- name: Make sure that apache2-utils is installed for htpasswd
ansible.builtin.package:
name: apache2-utils
state: present
- name: Create htpasswd file with user and password
expect:
command: "htpasswd -Bc /var/lib/{{ host_directory }}/auth/registry.passwd {{ username }}"
responses:
(?i)New password: "{{ password }}"
(?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"