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.yml

72 lines
3 KiB
YAML
Raw Normal View History

---
2020-03-09 10:11:07 +01:00
- name: Register registry cleanup
# This must be done **before** docker is set up (see next task), to ensure that the
# registry is removed **before** docker itself is removed. This is necessary as the
# registry and its frontends run as docker containers.
2020-03-09 10:11:07 +01:00
command: 'true'
notify: Remove test registry
2020-03-09 10:11:07 +01:00
- name: Setup Docker
# Please note that we do setup_docker here and not via meta/main.yml to avoid the problem that
# our cleanup is called **after** setup_docker's cleanup has been called!
2020-03-09 10:11:07 +01:00
include_role:
name: setup_docker
2020-03-09 10:11:07 +01:00
- name: Create random name prefix and test registry name
set_fact:
docker_registry_container_name_registry: '{{ ''ansible-test-registry-%0x'' % ((2**32) | random) }}'
docker_registry_container_name_nginx: '{{ ''ansible-test-registry-frontend-%0x'' % ((2**32) | random) }}'
docker_registry_container_name_nginx2: '{{ ''ansible-test-registry-frontend2-%0x'' % ((2**32) | random) }}'
2020-03-09 10:11:07 +01:00
- name: Create image and container list
set_fact:
docker_registry_setup_inames: []
docker_registry_setup_cnames:
- '{{ docker_registry_container_name_registry }}'
- '{{ docker_registry_container_name_nginx }}'
- '{{ docker_registry_container_name_nginx2 }}'
docker_registry_setup_vnames:
- '{{ docker_registry_container_name_nginx }}'
- '{{ docker_registry_container_name_nginx2 }}'
2020-03-09 10:11:07 +01:00
- debug:
msg: Using test registry name {{ docker_registry_container_name_registry }} and nginx frontend names {{ docker_registry_container_name_nginx }} and {{ docker_registry_container_name_nginx2 }}
- fail: msg="Too old docker / docker-py version to set up docker registry!"
when: not(docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')) and (ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6)
- when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
block:
# Set up registry container
2020-03-09 10:11:07 +01:00
- name: Start test registry
docker_container:
name: '{{ docker_registry_container_name_registry }}'
image: "{{ docker_test_image_registry }}"
2020-03-09 10:11:07 +01:00
ports: 5000
register: registry_container
2020-03-09 10:11:07 +01:00
- name: Get registry URL
set_fact:
registry_address: localhost:{{ registry_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
# Set up first nginx frontend for registry
- include_tasks: setup-frontend.yml
vars:
docker_registry_container_name_frontend: '{{ docker_registry_container_name_nginx }}'
- set_fact:
registry_frontend_address: '{{ docker_registry_frontend_address }}'
# Set up second nginx frontend for registry
- include_tasks: setup-frontend.yml
vars:
docker_registry_container_name_frontend: '{{ docker_registry_container_name_nginx2 }}'
- set_fact:
registry_frontend2_address: '{{ docker_registry_frontend_address }}'
# Print addresses for registry and frontends
- debug:
msg: "Registry available under {{ registry_address }}, NGINX frontends available under {{ registry_frontend_address }} and {{ registry_frontend2_address }}"