mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
a1ec307d43
* Make labels work with older docker daemon versions. * Fix idempotence detection. * Add changelog.
108 lines
2.8 KiB
YAML
108 lines
2.8 KiB
YAML
---
|
|
- block:
|
|
- name: Make sure we're not already using Docker swarm
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|
|
|
|
- name: Test parameters with state=join
|
|
docker_swarm:
|
|
state: join
|
|
ignore_errors: yes
|
|
register: output
|
|
|
|
- name: assert failure when called with state=join and no advertise_addr,remote_addrs,join_token
|
|
assert:
|
|
that:
|
|
- 'output.failed'
|
|
- 'output.msg == "state is join but all of the following are missing: advertise_addr, remote_addrs, join_token"'
|
|
|
|
- name: Test parameters with state=remove
|
|
docker_swarm:
|
|
state: remove
|
|
ignore_errors: yes
|
|
register: output
|
|
|
|
- name: assert failure when called with state=remove and no node_id
|
|
assert:
|
|
that:
|
|
- 'output.failed'
|
|
- 'output.msg == "state is remove but all of the following are missing: node_id"'
|
|
|
|
- name: Create a Swarm cluster (check mode)
|
|
docker_swarm:
|
|
state: present
|
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
|
check_mode: yes
|
|
register: output_1
|
|
|
|
- name: Create a Swarm cluster
|
|
docker_swarm:
|
|
state: present
|
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
|
register: output_2
|
|
|
|
- name: Create a Swarm cluster (idempotent)
|
|
docker_swarm:
|
|
state: present
|
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
|
register: output_3
|
|
|
|
- name: Create a Swarm cluster (idempotent, check mode)
|
|
docker_swarm:
|
|
state: present
|
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
|
check_mode: yes
|
|
register: output_4
|
|
|
|
- name: assert changed when create a new swarm cluster
|
|
assert:
|
|
that:
|
|
- 'output_1 is changed'
|
|
- 'output_2 is changed'
|
|
- 'output_2.actions[0] | regex_search("New Swarm cluster created: ")'
|
|
- 'output_2.swarm_facts.JoinTokens.Manager'
|
|
- 'output_2.swarm_facts.JoinTokens.Worker'
|
|
- 'output_3 is not changed'
|
|
- 'output_4 is not changed'
|
|
|
|
- name: Remove a Swarm cluster (check mode)
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|
|
check_mode: yes
|
|
register: output_1
|
|
|
|
- name: Remove a Swarm cluster
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|
|
register: output_2
|
|
|
|
- name: Remove a Swarm cluster (idempotent)
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|
|
register: output_3
|
|
|
|
- name: Remove a Swarm cluster (idempotent, check mode)
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|
|
check_mode: yes
|
|
register: output_4
|
|
|
|
- name: assert changed when remove a swarm cluster
|
|
assert:
|
|
that:
|
|
- 'output_1 is changed'
|
|
- 'output_2 is changed'
|
|
- 'output_2.actions[0] == "Node has left the swarm cluster"'
|
|
- 'output_3 is not changed'
|
|
- 'output_4 is not changed'
|
|
|
|
always:
|
|
- name: Cleanup
|
|
docker_swarm:
|
|
state: absent
|
|
force: true
|