1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Don't die when docker CLI doesn't want to work with docker daemon (#366)

* Don't die when docker CLI doesn't want to work with docker daemon.

* Allow more 'docker volume ls' failures

* More.

* Fix more failures.

* Forgot ignore_errors.

* Another one.

* More places.

* Try to install newer docker on RHEL8.

* Also restrict docker-ce-cli.
This commit is contained in:
Felix Fontein 2020-05-20 08:40:04 +02:00 committed by GitHub
parent 49f56697bb
commit 6fca49f445
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 251 additions and 181 deletions

View file

@ -53,6 +53,7 @@
- name: Inspect config - name: Inspect config
command: "docker config inspect {{ config_id }}" command: "docker config inspect {{ config_id }}"
register: inspect register: inspect
ignore_errors: yes
- debug: var=inspect - debug: var=inspect
@ -61,6 +62,11 @@
that: that:
- "'db_password' in inspect.stdout" - "'db_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout" - "'ansible_key' in inspect.stdout"
when: inspect is not failed
- assert:
that:
- "'is too new. Maximum supported API version is' in inspect.stderr"
when: inspect is failed
- name: Create config again - name: Create config again
docker_config: docker_config:

View file

@ -39,17 +39,28 @@
- name: "Comparison: use 'docker inspect'" - name: "Comparison: use 'docker inspect'"
command: docker inspect "{{ cname }}" command: docker inspect "{{ cname }}"
register: docker_inspect register: docker_inspect
ignore_errors: yes
- block:
- set_fact: - set_fact:
docker_inspect_result: "{{ docker_inspect.stdout | from_json }}" docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
- name: Dump docker inspect result - name: Dump docker inspect result
debug: var=docker_inspect_result debug: var=docker_inspect_result
when: docker_inspect is not failed
- assert: - assert:
that: that:
- result.exists - result.exists
- "'container' in result" - "'container' in result"
- "result.container" - "result.container"
- assert:
that:
- "result.container == docker_inspect_result[0]" - "result.container == docker_inspect_result[0]"
when: docker_inspect is not failed
- assert:
that:
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
when: docker_inspect is failed
always: always:
- name: Cleanup - name: Cleanup

View file

@ -1,4 +1,5 @@
--- ---
- block:
- name: Log in with wrong password (check mode) - name: Log in with wrong password (check mode)
docker_login: docker_login:
registry_url: "{{ registry_frontend_address }}" registry_url: "{{ registry_frontend_address }}"
@ -134,3 +135,5 @@
- logout_2 is changed - logout_2 is changed
- logout_3 is not changed - logout_3 is not changed
- logout_4 is not changed - logout_4 is not changed
when: registry_frontend_address != 'n/a'

View file

@ -36,10 +36,13 @@
- name: "Comparison: use 'docker network inspect'" - name: "Comparison: use 'docker network inspect'"
command: docker network inspect "{{ nname }}" command: docker network inspect "{{ nname }}"
register: docker_inspect register: docker_inspect
ignore_errors: yes
- block:
- set_fact: - set_fact:
docker_inspect_result: "{{ docker_inspect.stdout | from_json }}" docker_inspect_result: "{{ docker_inspect.stdout | from_json }}"
- name: Dump docker inspect result - name: Dump docker inspect result
debug: var=docker_inspect_result debug: var=docker_inspect_result
when: docker_inspect is not failed
- name: Cleanup - name: Cleanup
docker_network: docker_network:
@ -52,7 +55,15 @@
- result.exists - result.exists
- "'network' in result" - "'network' in result"
- "result.network" - "result.network"
- assert:
that:
- "result.network == docker_inspect_result[0]" - "result.network == docker_inspect_result[0]"
when: docker_inspect is not failed
- assert:
that:
- "'is too new. Maximum supported API version is' in docker_inspect.stderr"
when: docker_inspect is failed
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.21', '>=') when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.21', '>=')

View file

@ -18,6 +18,7 @@
become: yes become: yes
- name: Wait for docker daemon to be fully restarted - name: Wait for docker daemon to be fully restarted
command: docker ps command: docker ps
ignore_errors: yes
- name: Cleanup - name: Cleanup
docker_swarm: docker_swarm:

View file

@ -49,6 +49,7 @@
- name: Inspect secret - name: Inspect secret
command: "docker secret inspect {{ secret_id }}" command: "docker secret inspect {{ secret_id }}"
register: inspect register: inspect
ignore_errors: yes
- debug: var=inspect - debug: var=inspect
@ -57,6 +58,11 @@
that: that:
- "'db_password' in inspect.stdout" - "'db_password' in inspect.stdout"
- "'ansible_key' in inspect.stdout" - "'ansible_key' in inspect.stdout"
when: inspect is not failed
- assert:
that:
- "'is too new. Maximum supported API version is' in inspect.stderr"
when: inspect is failed
- name: Create secret again - name: Create secret again
docker_secret: docker_secret:

View file

@ -34,10 +34,13 @@
- name: "Comparison: use 'docker volume inspect'" - name: "Comparison: use 'docker volume inspect'"
command: docker volume inspect "{{ cname }}" command: docker volume inspect "{{ cname }}"
register: docker_volume_inspect register: docker_volume_inspect
ignore_errors: yes
- block:
- set_fact: - set_fact:
docker_volume_inspect_result: "{{ docker_volume_inspect.stdout | from_json }}" docker_volume_inspect_result: "{{ docker_volume_inspect.stdout | from_json }}"
- name: Dump docker volume inspect result - name: Dump docker volume inspect result
debug: var=docker_volume_inspect_result debug: var=docker_volume_inspect_result
when: docker_volume_inspect is not failed
- name: Cleanup - name: Cleanup
docker_volume: docker_volume:
@ -49,7 +52,15 @@
- result.exists - result.exists
- "'volume' in result" - "'volume' in result"
- "result.volume" - "result.volume"
- assert:
that:
- "result.volume == docker_volume_inspect_result[0]" - "result.volume == docker_volume_inspect_result[0]"
when: docker_volume_inspect is not failed
- assert:
that:
- "'is too new. Maximum supported API version is' in docker_volume_inspect.stderr"
when: docker_volume_inspect is failed
# Requirements for docker_volume # Requirements for docker_volume
when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.24', '>=') when: docker_py_version is version('1.10.0', '>=') and docker_api_version is version('1.24', '>=')

View file

@ -66,49 +66,56 @@
retries: 3 retries: 3
delay: 3 delay: 3
until: docker_containers is success until: docker_containers is success
ignore_errors: yes
- name: "Remove all ansible-test-* docker volumes" - name: "Remove all ansible-test-* docker volumes"
shell: 'docker volume ls --format {% raw %}"{{.Name}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker volume rm -f' shell: 'docker volume ls --format {% raw %}"{{.Name}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker volume rm -f'
register: docker_volumes register: docker_volumes
ignore_errors: yes
- name: "Remove all ansible-test-* docker networks" - name: "Remove all ansible-test-* docker networks"
shell: 'docker network ls --no-trunc --format {% raw %}"{{.Name}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker network rm' shell: 'docker network ls --no-trunc --format {% raw %}"{{.Name}}"{% endraw %} | grep "^ansible-test-" | xargs -r docker network rm'
register: docker_networks register: docker_networks
ignore_errors: yes
- name: Cleaned docker resources - name: Cleaned docker resources
debug: debug:
var: docker_resources var: docker_resources
vars: vars:
docker_resources: docker_resources:
containers: "{{ docker_containers.stdout_lines }}" containers: "{{ docker_containers.stdout_lines | default([]) }}"
volumes: "{{ docker_volumes.stdout_lines }}" volumes: "{{ docker_volumes.stdout_lines | default([]) }}"
networks: "{{ docker_networks.stdout_lines }}" networks: "{{ docker_networks.stdout_lines | default([]) }}"
# List all existing docker resources # List all existing docker resources
- name: List all docker containers - name: List all docker containers
command: docker ps --no-trunc -a command: docker ps --no-trunc -a
register: docker_containers register: docker_containers
ignore_errors: yes
- name: List all docker volumes - name: List all docker volumes
command: docker volume ls command: docker volume ls
register: docker_volumes register: docker_volumes
ignore_errors: yes
- name: List all docker networks - name: List all docker networks
command: docker network ls --no-trunc command: docker network ls --no-trunc
register: docker_networks register: docker_networks
ignore_errors: yes
- name: List all docker images - name: List all docker images
command: docker images --no-trunc -a command: docker images --no-trunc -a
register: docker_images register: docker_images
ignore_errors: yes
- name: Still existing docker resources - name: Still existing docker resources
debug: debug:
var: docker_resources var: docker_resources
vars: vars:
docker_resources: docker_resources:
containers: "{{ docker_containers.stdout_lines }}" containers: "{{ docker_containers.stdout_lines | default([]) }}"
volumes: "{{ docker_volumes.stdout_lines }}" volumes: "{{ docker_volumes.stdout_lines | default([]) }}"
networks: "{{ docker_networks.stdout_lines }}" networks: "{{ docker_networks.stdout_lines | default([]) }}"
images: "{{ docker_images.stdout_lines }}" images: "{{ docker_images.stdout_lines | default([]) }}"
when: docker_cli_version is version('0.0', '>') when: docker_cli_version is version('0.0', '>')

View file

@ -7,3 +7,4 @@ docker_prereq_packages:
# Docker CE > 3:18.09.1 requires containerd.io >= 1.2.2-3 which is unavaible at this time # Docker CE > 3:18.09.1 requires containerd.io >= 1.2.2-3 which is unavaible at this time
docker_packages: docker_packages:
- docker-ce-3:18.09.1 - docker-ce-3:18.09.1
- docker-ce-cli-1:18.09.1 # otherwise 19.03.9 is installed, which won't work with docker daemon 18.09.1

View file

@ -7,14 +7,20 @@
command: "docker logs {{ registry_name }}" command: "docker logs {{ registry_name }}"
register: registry_logs register: registry_logs
no_log: yes no_log: yes
ignore_errors: yes
- name: "Printing registry logs" - name: "Printing registry logs"
debug: var=registry_logs.stdout_lines debug:
var: registry_logs.stdout_lines
when: registry_logs is not failed
- name: "Get nginx logs" - name: "Get nginx logs"
command: "docker logs {{ nginx_name }}" command: "docker logs {{ nginx_name }}"
register: nginx_logs register: nginx_logs
no_log: yes no_log: yes
ignore_errors: yes
- name: "Printing nginx logs" - name: "Printing nginx logs"
debug: var=nginx_logs.stdout_lines debug:
var: nginx_logs.stdout_lines
when: nginx_logs is not failed
- name: "Make sure all containers are removed" - name: "Make sure all containers are removed"
docker_container: docker_container:
name: "{{ item }}" name: "{{ item }}"

View file

@ -52,6 +52,9 @@
loop: loop:
- nginx.conf - nginx.conf
- nginx.htpasswd - nginx.htpasswd
register: can_copy_files
ignore_errors: yes
- block:
- name: Create private key for frontend certificate - name: Create private key for frontend certificate
community.crypto.openssl_privatekey: community.crypto.openssl_privatekey:
path: '{{ output_dir }}/cert.key' path: '{{ output_dir }}/cert.key'
@ -93,6 +96,10 @@
- name: Get registry URL - name: Get registry URL
set_fact: set_fact:
registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }} registry_frontend_address: localhost:{{ nginx_container.container.NetworkSettings.Ports['5000/tcp'].0.HostPort }}
when: can_copy_files is not failed
- set_fact:
registry_frontend_address: 'n/a'
when: can_copy_files is failed
- debug: msg="Registry available under {{ registry_address }}, NGINX frontend available under {{ registry_frontend_address }}" - debug: msg="Registry available under {{ registry_address }}, NGINX frontend available under {{ registry_frontend_address }}"
when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=') when: docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
- fail: msg="Too old docker / docker-py version to run docker_image tests!" - fail: msg="Too old docker / docker-py version to run docker_image tests!"