mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
docker_swarm_service_info: Read information about swarm services (#55008)
* Add docker_swarm_service_info module * Remove unused import * Limit to retrieving info about one service * Add exists return value * Add yaml 3-dash Co-Authored-By: hannseman <hannes@5monkeys.se> * Document return value as jinja `none´ Co-Authored-By: hannseman <hannes@5monkeys.se> * Name is required
This commit is contained in:
parent
21ec3b294f
commit
23d0d225f4
6 changed files with 222 additions and 1 deletions
|
@ -4,7 +4,6 @@
|
|||
|
||||
import json
|
||||
from time import sleep
|
||||
from re import split
|
||||
|
||||
try:
|
||||
from docker.errors import APIError
|
||||
|
@ -249,3 +248,29 @@ class AnsibleDockerSwarmClient(AnsibleDockerClient):
|
|||
if self.docker_py_version < LooseVersion('2.7.0'):
|
||||
return None
|
||||
return super(AnsibleDockerSwarmClient, self).get_unlock_key()
|
||||
|
||||
def get_service_inspect(self, service_id, skip_missing=False):
|
||||
"""
|
||||
Returns Swarm service info as in 'docker service inspect' command about single service
|
||||
|
||||
:param service_id: service ID or name
|
||||
:param skip_missing: if True then function will return None instead of failing the task
|
||||
:return:
|
||||
Single service information structure
|
||||
"""
|
||||
try:
|
||||
service_info = self.inspect_service(service=service_id)
|
||||
except APIError as exc:
|
||||
if exc.status_code == 503:
|
||||
self.fail("Cannot inspect service: To inspect service execute module on Swarm Manager")
|
||||
if exc.status_code == 404:
|
||||
if skip_missing is False:
|
||||
self.fail("Error while reading from Swarm manager: %s" % to_native(exc))
|
||||
else:
|
||||
return None
|
||||
except Exception as exc:
|
||||
self.fail("Error inspecting swarm service: %s" % exc)
|
||||
|
||||
json_str = json.dumps(service_info, ensure_ascii=False)
|
||||
service_info = json.loads(json_str)
|
||||
return service_info
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue