1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00
community.general/tests/integration/targets/setup_docker_registry/tasks/setup-frontend.yml

86 lines
2.5 KiB
YAML
Raw Normal View History

---
# Set up first nginx frontend for registry
- name: Start nginx frontend for registry
docker_volume:
name: '{{ docker_registry_container_name_frontend }}'
state: present
- name: Create container for nginx frontend for registry
docker_container:
state: stopped
name: '{{ docker_registry_container_name_frontend }}'
image: nginx:alpine
ports: 5000
links:
- '{{ docker_registry_container_name_registry }}:real-registry'
volumes:
- '{{ docker_registry_container_name_frontend }}:/etc/nginx/'
register: nginx_container
- name: Copy static files into volume
command: docker cp {{ role_path }}/files/{{ item }} {{ docker_registry_container_name_frontend }}:/etc/nginx/{{ item }}
loop:
- nginx.conf
- nginx.htpasswd
register: can_copy_files
ignore_errors: yes
- when: can_copy_files is not failed
block:
- name: Create private key for frontend certificate
community.crypto.openssl_privatekey:
path: '{{ output_dir }}/cert.key'
type: ECC
curve: secp256r1
force: yes
- name: Create CSR for frontend certificate
community.crypto.openssl_csr:
path: '{{ output_dir }}/cert.csr'
privatekey_path: '{{ output_dir }}/cert.key'
subject_alt_name:
- DNS:test-registry.ansible.com
- name: Create frontend certificate
community.crypto.openssl_certificate:
path: '{{ output_dir }}/cert.pem'
csr_path: '{{ output_dir }}/cert.csr'
privatekey_path: '{{ output_dir }}/cert.key'
provider: selfsigned
- name: Copy dynamic files into volume
command: docker cp {{ output_dir }}/{{ item }} {{ docker_registry_container_name_frontend }}:/etc/nginx/{{ item }}
loop:
- cert.pem
- cert.key
- name: Start nginx frontend for registry
docker_container:
name: '{{ docker_registry_container_name_frontend }}'
state: started
register: nginx_container
- name: Output nginx container network settings
debug:
var: nginx_container.container.NetworkSettings
- name: Wait for registry frontend
uri:
url: https://{{ nginx_container.container.NetworkSettings.IPAddress }}:5000/v2/
url_username: testuser
url_password: hunter2
validate_certs: false
register: result
until: result is success
retries: 5
delay: 1
- name: Get registry URL
set_fact:
docker_registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
- set_fact:
docker_registry_frontend_address: 'n/a'
when: can_copy_files is failed