Files
playbooks/registry/roles/registry/tasks/main.yaml
T
2024-12-17 17:53:30 +05:30

51 lines
1.4 KiB
YAML

---
# 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"