2018-11-06 16:08:28 +01:00
---
- block :
- name : Create random container name
set_fact :
cname : "{{ 'ansible-test-%0x' % ((2**32) | random) }}"
- name : Make sure container is not there
docker_container :
name : "{{ cname }}"
state : absent
2018-11-16 13:37:12 +01:00
force_kill : yes
2018-11-06 16:08:28 +01:00
- name : Inspect a non-present container
2019-03-21 09:37:18 +01:00
docker_container_info :
2018-11-06 16:08:28 +01:00
name : "{{ cname }}"
register : result
- assert :
that :
- "not result.exists"
2019-03-05 17:09:00 +01:00
- "'container' in result"
- "result.container is none"
2018-11-06 16:08:28 +01:00
- name : Make sure container exists
docker_container :
name : "{{ cname }}"
image : alpine:3.8
command : '/bin/sh -c "sleep 10m"'
state : started
auto_remove : yes
2018-11-16 13:37:12 +01:00
force_kill : yes
2018-11-06 16:08:28 +01:00
- name : Inspect a present container
2019-03-21 09:37:18 +01:00
docker_container_info :
2018-11-06 16:08:28 +01:00
name : "{{ cname }}"
register : result
2019-03-21 09:37:18 +01:00
- name : Dump docker_container_info result
2018-11-06 16:08:28 +01:00
debug : var=result
- name : "Comparison: use 'docker inspect'"
command : docker inspect "{{ cname }}"
register : docker_inspect
- set_fact :
docker_inspect_result : "{{ docker_inspect.stdout | from_json }}"
- name : Dump docker inspect result
debug : var=docker_inspect_result
- name : Cleanup
docker_container :
name : "{{ cname }}"
state : absent
2018-11-16 13:37:12 +01:00
force_kill : yes
2018-11-06 16:08:28 +01:00
- assert :
that :
- result.exists
2019-03-05 17:09:00 +01:00
- "'container' in result"
- "result.container"
- "result.container == docker_inspect_result[0]"
2018-11-06 16:08:28 +01:00
2018-11-19 11:01:40 +01:00
when : docker_py_version is version('1.8.0', '>=') and docker_api_version is version('1.20', '>=')
2019-03-21 09:37:18 +01:00
- fail : msg="Too old docker / docker-py version to run docker_container_info tests!"
2018-11-19 11:01:40 +01:00
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)