62 lines
1.5 KiB
YAML
62 lines
1.5 KiB
YAML
---
|
|
- 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
|
|
force_kill: yes
|
|
|
|
- name: Inspect a non-present container
|
|
docker_container_facts:
|
|
name: "{{ cname }}"
|
|
register: result
|
|
|
|
- assert:
|
|
that:
|
|
- "not result.exists"
|
|
- "'docker_container' in result"
|
|
- "not result.docker_container"
|
|
|
|
- name: Make sure container exists
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
state: started
|
|
auto_remove: yes
|
|
force_kill: yes
|
|
|
|
- name: Inspect a present container
|
|
docker_container_facts:
|
|
name: "{{ cname }}"
|
|
register: result
|
|
- name: Dump docker_container_facts result
|
|
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
|
|
force_kill: yes
|
|
|
|
- assert:
|
|
that:
|
|
- result.exists
|
|
- "'docker_container' in result"
|
|
- "result.docker_container"
|
|
- "result.docker_container == docker_inspect_result[0]"
|
|
|
|
# Skip for CentOS 6
|
|
when: ansible_distribution != 'CentOS' or ansible_distribution_major_version|int > 6
|