mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix force when state==present. (#53003)
This commit is contained in:
parent
dec97381bc
commit
76e0e0080b
3 changed files with 29 additions and 5 deletions
|
@ -0,0 +1,2 @@
|
||||||
|
bugfixes:
|
||||||
|
- "docker_swarm - the ``force`` option was ignored when ``state: present``."
|
|
@ -255,7 +255,6 @@ class TaskParameters(DockerBaseClass):
|
||||||
|
|
||||||
self.advertise_addr = None
|
self.advertise_addr = None
|
||||||
self.listen_addr = None
|
self.listen_addr = None
|
||||||
self.force_new_cluster = None
|
|
||||||
self.remote_addrs = None
|
self.remote_addrs = None
|
||||||
self.join_token = None
|
self.join_token = None
|
||||||
|
|
||||||
|
@ -356,8 +355,8 @@ class TaskParameters(DockerBaseClass):
|
||||||
|
|
||||||
def compare_to_active(self, other, differences):
|
def compare_to_active(self, other, differences):
|
||||||
for k in self.__dict__:
|
for k in self.__dict__:
|
||||||
if k in ('advertise_addr', 'listen_addr', 'force_new_cluster', 'remote_addrs',
|
if k in ('advertise_addr', 'listen_addr', 'remote_addrs', 'join_token',
|
||||||
'join_token', 'force', 'rotate_worker_token', 'rotate_manager_token', 'spec'):
|
'rotate_worker_token', 'rotate_manager_token', 'spec'):
|
||||||
continue
|
continue
|
||||||
if self.__dict__[k] is None:
|
if self.__dict__[k] is None:
|
||||||
continue
|
continue
|
||||||
|
@ -419,7 +418,7 @@ class SwarmManager(DockerBaseClass):
|
||||||
return
|
return
|
||||||
|
|
||||||
def init_swarm(self):
|
def init_swarm(self):
|
||||||
if self.client.check_if_swarm_manager():
|
if not self.force and self.client.check_if_swarm_manager():
|
||||||
self.__update_swarm()
|
self.__update_swarm()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -427,7 +426,7 @@ class SwarmManager(DockerBaseClass):
|
||||||
try:
|
try:
|
||||||
self.client.init_swarm(
|
self.client.init_swarm(
|
||||||
advertise_addr=self.parameters.advertise_addr, listen_addr=self.parameters.listen_addr,
|
advertise_addr=self.parameters.advertise_addr, listen_addr=self.parameters.listen_addr,
|
||||||
force_new_cluster=self.parameters.force_new_cluster, swarm_spec=self.parameters.spec)
|
force_new_cluster=self.force, swarm_spec=self.parameters.spec)
|
||||||
except APIError as exc:
|
except APIError as exc:
|
||||||
self.client.fail("Can not create a new Swarm Cluster: %s" % to_native(exc))
|
self.client.fail("Can not create a new Swarm Cluster: %s" % to_native(exc))
|
||||||
|
|
||||||
|
|
|
@ -61,6 +61,23 @@
|
||||||
diff: yes
|
diff: yes
|
||||||
register: output_4
|
register: output_4
|
||||||
|
|
||||||
|
- name: Create a Swarm cluster (force re-create)
|
||||||
|
docker_swarm:
|
||||||
|
state: present
|
||||||
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||||
|
force: yes
|
||||||
|
diff: yes
|
||||||
|
register: output_5
|
||||||
|
|
||||||
|
- name: Create a Swarm cluster (force re-create, check mode)
|
||||||
|
docker_swarm:
|
||||||
|
state: present
|
||||||
|
advertise_addr: "{{ansible_default_ipv4.address}}"
|
||||||
|
force: yes
|
||||||
|
check_mode: yes
|
||||||
|
diff: yes
|
||||||
|
register: output_6
|
||||||
|
|
||||||
- name: assert changed when create a new swarm cluster
|
- name: assert changed when create a new swarm cluster
|
||||||
assert:
|
assert:
|
||||||
that:
|
that:
|
||||||
|
@ -79,6 +96,12 @@
|
||||||
- 'output_4 is not changed'
|
- 'output_4 is not changed'
|
||||||
- 'output_4.diff.before is defined'
|
- 'output_4.diff.before is defined'
|
||||||
- 'output_4.diff.after is defined'
|
- 'output_4.diff.after is defined'
|
||||||
|
- 'output_5 is changed'
|
||||||
|
- 'output_5.diff.before is defined'
|
||||||
|
- 'output_5.diff.after is defined'
|
||||||
|
- 'output_6 is changed'
|
||||||
|
- 'output_6.diff.before is defined'
|
||||||
|
- 'output_6.diff.after is defined'
|
||||||
|
|
||||||
####################################################################
|
####################################################################
|
||||||
## Removal #########################################################
|
## Removal #########################################################
|
||||||
|
|
Loading…
Reference in a new issue