2018-10-06 15:50:31 +02:00
|
|
|
---
|
|
|
|
- name: Registering container name
|
|
|
|
set_fact:
|
|
|
|
cname: "{{ cname_prefix ~ '-iid' }}"
|
|
|
|
- name: Registering container name
|
|
|
|
set_fact:
|
|
|
|
cnames: "{{ cnames }} + [cname]"
|
|
|
|
|
|
|
|
- name: Pull images
|
|
|
|
docker_image:
|
2019-03-11 10:04:06 +01:00
|
|
|
name: "{{ image }}"
|
2018-10-06 15:50:31 +02:00
|
|
|
pull: true
|
|
|
|
loop:
|
|
|
|
- "hello-world:latest"
|
|
|
|
- "alpine:3.8"
|
2019-03-11 10:04:06 +01:00
|
|
|
loop_control:
|
|
|
|
loop_var: image
|
2018-10-06 15:50:31 +02:00
|
|
|
|
|
|
|
- name: Get image ID of hello-world and alpine images
|
|
|
|
docker_image_facts:
|
|
|
|
name:
|
|
|
|
- "hello-world:latest"
|
|
|
|
- "alpine:3.8"
|
|
|
|
register: image_facts
|
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- image_facts.images | length == 2
|
|
|
|
|
|
|
|
- name: Print image IDs
|
|
|
|
debug:
|
|
|
|
msg: "hello-world: {{ image_facts.images[0].Id }}; alpine: {{ image_facts.images[1].Id }}"
|
|
|
|
|
|
|
|
- name: Create container with hello-world image via ID
|
|
|
|
docker_container:
|
|
|
|
image: "{{ image_facts.images[0].Id }}"
|
|
|
|
name: "{{ cname }}"
|
|
|
|
state: present
|
2018-11-16 13:37:12 +01:00
|
|
|
force_kill: yes
|
2018-10-06 15:50:31 +02:00
|
|
|
register: create_1
|
|
|
|
|
|
|
|
- name: Create container with hello-world image via ID (idempotent)
|
|
|
|
docker_container:
|
|
|
|
image: "{{ image_facts.images[0].Id }}"
|
|
|
|
name: "{{ cname }}"
|
|
|
|
state: present
|
2018-11-16 13:37:12 +01:00
|
|
|
force_kill: yes
|
2018-10-06 15:50:31 +02:00
|
|
|
register: create_2
|
|
|
|
|
|
|
|
- name: Create container with alpine image via ID
|
|
|
|
docker_container:
|
|
|
|
image: "{{ image_facts.images[1].Id }}"
|
|
|
|
name: "{{ cname }}"
|
|
|
|
state: present
|
2018-11-16 13:37:12 +01:00
|
|
|
force_kill: yes
|
2018-10-06 15:50:31 +02:00
|
|
|
register: create_3
|
|
|
|
|
|
|
|
- name: Create container with alpine image via ID (idempotent)
|
|
|
|
docker_container:
|
|
|
|
image: "{{ image_facts.images[1].Id }}"
|
|
|
|
name: "{{ cname }}"
|
|
|
|
state: present
|
2018-11-16 13:37:12 +01:00
|
|
|
force_kill: yes
|
2018-10-06 15:50:31 +02:00
|
|
|
register: create_4
|
|
|
|
|
|
|
|
- name: Cleanup
|
|
|
|
docker_container:
|
|
|
|
name: "{{ cname }}"
|
|
|
|
state: absent
|
2018-11-16 13:37:12 +01:00
|
|
|
force_kill: yes
|
2018-11-19 10:59:54 +01:00
|
|
|
diff: no
|
2018-10-06 15:50:31 +02:00
|
|
|
|
|
|
|
- assert:
|
|
|
|
that:
|
|
|
|
- create_1 is changed
|
|
|
|
- create_2 is not changed
|
|
|
|
- create_3 is changed
|
|
|
|
- create_4 is not changed
|