summaryrefslogtreecommitdiff
path: root/test/integration/targets/docker_container/tasks/tests/image-ids.yml
blob: 402c69521d320fdde94cb1e23010ecd1de48a7bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
---
- name: Registering container name
  set_fact:
    cname: "{{ cname_prefix ~ '-iid' }}"
- name: Registering container name
  set_fact:
    cnames: "{{ cnames }} + [cname]"

- name: Pull images
  docker_image:
    name: "{{ item }}"
    pull: true
  loop:
    - "hello-world:latest"
    - "alpine:3.8"

- 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
    force_kill: yes
  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
    force_kill: yes
  register: create_2

- name: Create container with alpine image via ID
  docker_container:
    image: "{{ image_facts.images[1].Id }}"
    name: "{{ cname }}"
    state: present
    force_kill: yes
  register: create_3

- name: Create container with alpine image via ID (idempotent)
  docker_container:
    image: "{{ image_facts.images[1].Id }}"
    name: "{{ cname }}"
    state: present
    force_kill: yes
  register: create_4

- name: Cleanup
  docker_container:
    name: "{{ cname }}"
    state: absent
    force_kill: yes

- assert:
    that:
      - create_1 is changed
      - create_2 is not changed
      - create_3 is changed
      - create_4 is not changed