mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
docker.swarm library docker bug workaround to provide correct swarm leader address (#53930)
* Workaround for moby/moby#35437 bug for ansible.docker.swarm library to provide correct leader node IP address * Adding simple parser to separate IP address from port number for workaround * Adding simple parser to separate IP address from port number for workaround (inline) * Different split() method
This commit is contained in:
parent
e2371d4b52
commit
2c473259cb
1 changed files with 12 additions and 0 deletions
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from time import sleep
|
from time import sleep
|
||||||
|
from re import split
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from docker.errors import APIError
|
from docker.errors import APIError
|
||||||
|
@ -166,6 +167,17 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
||||||
|
|
||||||
json_str = json.dumps(node_info, ensure_ascii=False)
|
json_str = json.dumps(node_info, ensure_ascii=False)
|
||||||
node_info = json.loads(json_str)
|
node_info = json.loads(json_str)
|
||||||
|
|
||||||
|
if 'ManagerStatus' in node_info:
|
||||||
|
if node_info['ManagerStatus'].get('Leader'):
|
||||||
|
# This is workaround of bug in Docker when in some cases the Leader IP is 0.0.0.0
|
||||||
|
# Check moby/moby#35437 for details
|
||||||
|
count_colons = node_info['ManagerStatus']['Addr'].count(":")
|
||||||
|
if count_colons == 1:
|
||||||
|
swarm_leader_ip = node_info['ManagerStatus']['Addr'].split(":", 1)[0] or node_info['Status']['Addr']
|
||||||
|
else:
|
||||||
|
swarm_leader_ip = node_info['Status']['Addr']
|
||||||
|
node_info['Status']['Addr'] = swarm_leader_ip
|
||||||
return node_info
|
return node_info
|
||||||
|
|
||||||
def get_all_nodes_inspect(self):
|
def get_all_nodes_inspect(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue