mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 12:50:22 -07:00
docker: provide alternatives to ansible_facts results (#51192)
* Try to stop using ansible_facts for docker modules. * Stop using facts returned from regular modules.
This commit is contained in:
parent
8222ebd23a
commit
37b0f5c81b
7 changed files with 50 additions and 26 deletions
|
@ -293,8 +293,12 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
RETURN = '''
|
||||
service:
|
||||
description: Name of the service.
|
||||
service_facts:
|
||||
description:
|
||||
- A dictionary mapping the service's name to a dictionary of containers.
|
||||
- Note that facts are part of the registered vars since Ansible 2.8. For compatibility reasons, the facts
|
||||
are also accessible directly. The service's name is the variable with which the container dictionary
|
||||
can be accessed.
|
||||
returned: success
|
||||
type: complex
|
||||
contains:
|
||||
|
@ -673,7 +677,7 @@ class ContainerManager(DockerBaseClass):
|
|||
start_deps = self.dependencies
|
||||
service_names = self.services
|
||||
detached = True
|
||||
result = dict(changed=False, actions=[], ansible_facts=dict())
|
||||
result = dict(changed=False, actions=[], ansible_facts=dict(), service_facts=dict())
|
||||
|
||||
up_options = {
|
||||
u'--no-recreate': False,
|
||||
|
@ -757,7 +761,9 @@ class ContainerManager(DockerBaseClass):
|
|||
result['actions'] += scale_output['actions']
|
||||
|
||||
for service in self.project.services:
|
||||
result['ansible_facts'][service.name] = dict()
|
||||
service_facts = dict()
|
||||
result['ansible_facts'][service.name] = service_facts
|
||||
result['service_facts'][service.name] = service_facts
|
||||
for container in service.containers(stopped=True):
|
||||
inspection = container.inspect()
|
||||
# pare down the inspection data to the most useful bits
|
||||
|
@ -809,7 +815,7 @@ class ContainerManager(DockerBaseClass):
|
|||
if networks[key].get('MacAddress', None) is not None:
|
||||
facts['networks'][key]['macAddress'] = networks[key]['MacAddress']
|
||||
|
||||
result['ansible_facts'][service.name][container.name] = facts
|
||||
service_facts[container.name] = facts
|
||||
|
||||
return result
|
||||
|
||||
|
|
|
@ -821,7 +821,8 @@ docker_container:
|
|||
description:
|
||||
- Before 2.3 this was 'ansible_docker_container' but was renamed due to conflicts with the connection plugin.
|
||||
- Facts representing the current state of the container. Matches the docker inspection output.
|
||||
- Note that facts are not part of registered vars but accessible directly.
|
||||
- Note that facts are part of the registered vars since Ansible 2.8. For compatibility reasons, the facts
|
||||
are also accessible directly.
|
||||
- Empty if C(state) is I(absent)
|
||||
- If detached is I(False), will include Output attribute containing any output from container run.
|
||||
returned: always
|
||||
|
@ -2196,6 +2197,7 @@ class ContainerManager(DockerBaseClass):
|
|||
|
||||
if self.facts:
|
||||
self.results['ansible_facts'] = {'docker_container': self.facts}
|
||||
self.results['docker_container'] = self.facts
|
||||
|
||||
def present(self, state):
|
||||
container = self._get_container(self.parameters.name)
|
||||
|
|
|
@ -246,8 +246,11 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: Network inspection results for the affected network.
|
||||
docker_network:
|
||||
description:
|
||||
- Network inspection results for the affected network.
|
||||
- Note that facts are part of the registered vars since Ansible 2.8. For compatibility reasons, the facts
|
||||
are also accessible directly.
|
||||
returned: success
|
||||
type: dict
|
||||
sample: {}
|
||||
|
@ -575,7 +578,9 @@ class DockerNetworkManager(object):
|
|||
if not self.check_mode and not self.parameters.debug:
|
||||
self.results.pop('actions')
|
||||
|
||||
self.results['ansible_facts'] = {u'docker_network': self.get_existing_network()}
|
||||
network_facts = self.get_existing_network()
|
||||
self.results['ansible_facts'] = {u'docker_network': network_facts}
|
||||
self.results['docker_network'] = network_facts
|
||||
|
||||
def absent(self):
|
||||
self.diff_tracker.add('exists', parameter=False, active=self.existing_network is not None)
|
||||
|
|
|
@ -113,8 +113,11 @@ EXAMPLES = '''
|
|||
'''
|
||||
|
||||
RETURN = '''
|
||||
facts:
|
||||
description: Volume inspection results for the affected volume.
|
||||
docker_volume:
|
||||
description:
|
||||
- Volume inspection results for the affected volume.
|
||||
- Note that facts are part of the registered vars since Ansible 2.8. For compatibility reasons, the facts
|
||||
are also accessible directly.
|
||||
returned: success
|
||||
type: dict
|
||||
sample: {}
|
||||
|
@ -284,7 +287,9 @@ class DockerVolumeManager(object):
|
|||
if not self.check_mode and not self.parameters.debug:
|
||||
self.results.pop('actions')
|
||||
|
||||
self.results['ansible_facts'] = {u'docker_volume': self.get_existing_volume()}
|
||||
volume_facts = self.get_existing_volume()
|
||||
self.results['ansible_facts'] = {u'docker_volume': volume_facts}
|
||||
self.results['docker_volume'] = volume_facts
|
||||
|
||||
def absent(self):
|
||||
self.diff_tracker.add('exists', parameter=False, active=self.existing_volume is not None)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue