mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
84682464c7
* Added comparison configuration. * Improving user feedback on specifying a wrong option. * Avoid bare except. * Added basic integration tests. * Adding wildcard support. * Warn if ignore_image=yes is overridden. * Added changelog fragment.
447 lines
10 KiB
YAML
447 lines
10 KiB
YAML
---
|
|
- name: Registering container name
|
|
set_fact:
|
|
cname: "{{ cname_prefix ~ '-comparisons' }}"
|
|
- name: Registering container name
|
|
set_fact:
|
|
cnames: "{{ cnames }} + [cname]"
|
|
|
|
####################################################################
|
|
## value ###########################################################
|
|
####################################################################
|
|
|
|
- name: value
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.com
|
|
register: value_1
|
|
|
|
- name: value (change, ignore)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.org
|
|
comparisons:
|
|
hostname: ignore
|
|
register: value_2
|
|
|
|
- name: value (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.org
|
|
stop_timeout: 1
|
|
comparisons:
|
|
hostname: strict
|
|
register: value_3
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- value_1 is changed
|
|
- value_2 is not changed
|
|
- value_3 is changed
|
|
|
|
####################################################################
|
|
## list ############################################################
|
|
####################################################################
|
|
|
|
- name: list
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
dns_servers:
|
|
- 1.1.1.1
|
|
- 8.8.8.8
|
|
register: list_1
|
|
|
|
- name: list (change, ignore)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
dns_servers:
|
|
- 9.9.9.9
|
|
comparisons:
|
|
dns_servers: ignore
|
|
register: list_2
|
|
|
|
- name: list (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
dns_servers:
|
|
- 9.9.9.9
|
|
comparisons:
|
|
dns_servers: strict
|
|
stop_timeout: 1
|
|
register: list_3
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- list_1 is changed
|
|
- list_2 is not changed
|
|
- list_3 is changed
|
|
|
|
####################################################################
|
|
## set #############################################################
|
|
####################################################################
|
|
|
|
- name: set
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
groups:
|
|
- 1010
|
|
- 1011
|
|
register: set_1
|
|
|
|
- name: set (change, ignore)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
groups:
|
|
- 1010
|
|
- 1011
|
|
- 1012
|
|
comparisons:
|
|
groups: ignore
|
|
register: set_2
|
|
|
|
- name: set (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
groups:
|
|
- 1010
|
|
- 1011
|
|
- 1012
|
|
comparisons:
|
|
groups: allow_more_present
|
|
stop_timeout: 1
|
|
register: set_3
|
|
|
|
- name: set (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
groups:
|
|
- 1010
|
|
- 1012
|
|
comparisons:
|
|
groups: allow_more_present
|
|
stop_timeout: 1
|
|
register: set_4
|
|
|
|
- name: set (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
groups:
|
|
- 1010
|
|
- 1012
|
|
comparisons:
|
|
groups: strict
|
|
stop_timeout: 1
|
|
register: set_5
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- set_1 is changed
|
|
- set_2 is not changed
|
|
- set_3 is changed
|
|
- set_4 is not changed
|
|
- set_5 is changed
|
|
|
|
####################################################################
|
|
## set(dict) #######################################################
|
|
####################################################################
|
|
|
|
- name: set(dict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
devices:
|
|
- "/dev/random:/dev/virt-random:rwm"
|
|
- "/dev/urandom:/dev/virt-urandom:rwm"
|
|
register: set_dict_1
|
|
|
|
- name: set(dict) (change, ignore)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
devices:
|
|
- "/dev/random:/dev/virt-random:rwm"
|
|
- "/dev/urandom:/dev/virt-urandom:rwm"
|
|
- "/dev/null:/dev/virt-null:rwm"
|
|
comparisons:
|
|
devices: ignore
|
|
register: set_dict_2
|
|
|
|
- name: set(dict) (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
devices:
|
|
- "/dev/random:/dev/virt-random:rwm"
|
|
- "/dev/urandom:/dev/virt-urandom:rwm"
|
|
- "/dev/null:/dev/virt-null:rwm"
|
|
comparisons:
|
|
devices: allow_more_present
|
|
stop_timeout: 1
|
|
register: set_dict_3
|
|
|
|
- name: set(dict) (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
devices:
|
|
- "/dev/random:/dev/virt-random:rwm"
|
|
- "/dev/null:/dev/virt-null:rwm"
|
|
comparisons:
|
|
devices: allow_more_present
|
|
stop_timeout: 1
|
|
register: set_dict_4
|
|
|
|
- name: set(dict) (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
devices:
|
|
- "/dev/random:/dev/virt-random:rwm"
|
|
- "/dev/null:/dev/virt-null:rwm"
|
|
comparisons:
|
|
devices: strict
|
|
stop_timeout: 1
|
|
register: set_dict_5
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- set_dict_1 is changed
|
|
- set_dict_2 is not changed
|
|
- set_dict_3 is changed
|
|
- set_dict_4 is not changed
|
|
- set_dict_5 is changed
|
|
|
|
####################################################################
|
|
## dict ############################################################
|
|
####################################################################
|
|
|
|
- name: dict
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
register: dict_1
|
|
|
|
- name: dict (change, ignore)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
labels: ignore
|
|
register: dict_2
|
|
|
|
- name: dict (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
labels: allow_more_present
|
|
stop_timeout: 1
|
|
register: dict_3
|
|
|
|
- name: dict (change, allow_more_present)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
labels: allow_more_present
|
|
stop_timeout: 1
|
|
register: dict_4
|
|
|
|
- name: dict (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
labels: strict
|
|
stop_timeout: 1
|
|
register: dict_5
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- dict_1 is changed
|
|
- dict_2 is not changed
|
|
- dict_3 is changed
|
|
- dict_4 is not changed
|
|
- dict_5 is changed
|
|
|
|
####################################################################
|
|
## wildcard ########################################################
|
|
####################################################################
|
|
|
|
- name: Pull hello-world image to make sure wildcard_2 test succeeds
|
|
# If the image isn't there, it will pull it and return 'changed'.
|
|
docker_image:
|
|
name: hello-world
|
|
pull: true
|
|
|
|
- name: wildcard
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.com
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
ansible.test.3: ansible
|
|
register: wildcard_1
|
|
|
|
- name: wildcard (change, ignore)
|
|
docker_container:
|
|
image: hello-world
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.org
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.4: ignore
|
|
comparisons:
|
|
'*': ignore
|
|
register: wildcard_2
|
|
|
|
- name: wildcard (change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.org
|
|
stop_timeout: 1
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
'*': strict
|
|
register: wildcard_3
|
|
|
|
- name: wildcard (no change, strict)
|
|
docker_container:
|
|
image: alpine:3.8
|
|
command: '/bin/sh -c "sleep 10m"'
|
|
name: "{{ cname }}"
|
|
state: started
|
|
hostname: example.org
|
|
stop_timeout: 1
|
|
labels:
|
|
ansible.test.1: hello
|
|
ansible.test.2: world
|
|
ansible.test.3: ansible
|
|
comparisons:
|
|
'*': strict
|
|
register: wildcard_4
|
|
|
|
- name: cleanup
|
|
docker_container:
|
|
name: "{{ cname }}"
|
|
state: absent
|
|
stop_timeout: 1
|
|
|
|
- assert:
|
|
that:
|
|
- wildcard_1 is changed
|
|
- wildcard_2 is not changed
|
|
- wildcard_3 is changed
|
|
- wildcard_4 is not changed
|