Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify docker_*_facts return names #51939

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 4 additions & 3 deletions changelogs/fragments/docker-facts.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
minor_changes:
- "docker_container, docker_network, docker_volume - return facts as regular variable additionally to
facts. This is now the preferred way to obtain results."
- "docker_container, docker_network, docker_volume - return facts as regular variables ``container``,
``network`` respectively ``volume`` additionally to facts. This is now the preferred way to
obtain results. The facts will be removed in Ansible 2.12."
- "docker_service - return facts as regular variable ``service_facts``; this is a dictionary mapping
service names to container dictionaries. The facts are still returned, but it is recommended to
use ``register`` and ``service_facts`` in the future."
use ``register`` and ``service_facts`` in the future. The facts will be removed in Ansible 2.12."
6 changes: 3 additions & 3 deletions docs/docsite/rst/porting_guides/porting_guide_2.8.rst
Original file line number Diff line number Diff line change
Expand Up @@ -276,11 +276,11 @@ Noteworthy module changes
This allows for more flexibility and better module support.

* The ``docker_container`` module has deprecated the returned fact ``docker_container``. The same value is
available as the returned variable ``docker_container``. The returned fact will be removed in Ansible 2.12.
available as the returned variable ``container``. The returned fact will be removed in Ansible 2.12.
* The ``docker_network`` module has deprecated the returned fact ``docker_container``. The same value is
available as the returned variable ``docker_network``. The returned fact will be removed in Ansible 2.12.
available as the returned variable ``network``. The returned fact will be removed in Ansible 2.12.
* The ``docker_volume`` module has deprecated the returned fact ``docker_container``. The same value is
available as the returned variable ``docker_volume``. The returned fact will be removed in Ansible 2.12.
available as the returned variable ``volume``. The returned fact will be removed in Ansible 2.12.

* The ``docker_service`` module was renamed to :ref:`docker_compose <docker_compose_module>`.
* The renamed ``docker_compose`` module used to return one fact per service, named same as the service. A dictionary
Expand Down
9 changes: 5 additions & 4 deletions lib/ansible/modules/cloud/docker/docker_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -873,12 +873,13 @@
'''

RETURN = '''
docker_container:
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 part of the registered vars since Ansible 2.8. For compatibility reasons, the facts
are also accessible directly. Note that the returned fact will be removed in Ansible 2.12.
are also accessible directly as C(docker_container). Note that the returned fact will be removed in Ansible 2.12.
- Before 2.3 this was C(ansible_docker_container) but was renamed in 2.3 to C(docker_container) due to
conflicts with the connection plugin.
- Empty if C(state) is I(absent)
- If detached is I(False), will include Output attribute containing any output from container run.
returned: always
Expand Down Expand Up @@ -2253,7 +2254,7 @@ def __init__(self, client):

if self.facts:
self.results['ansible_facts'] = {'docker_container': self.facts}
self.results['docker_container'] = self.facts
self.results['container'] = self.facts

def present(self, state):
container = self._get_container(self.parameters.name)
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_container_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

- name: Print information about container
debug:
var: result.docker_container
var: result.container
when: result.exists
'''

Expand All @@ -67,7 +67,7 @@
type: bool
returned: always
sample: true
docker_container:
container:
description:
- Facts representing the current state of the container. Matches the docker inspection output.
- Will be C(None) if container does not exist.
Expand Down Expand Up @@ -126,7 +126,7 @@ def main():
client.module.exit_json(
changed=False,
exists=(True if container else False),
docker_container=container,
container=container,
)


Expand Down
19 changes: 9 additions & 10 deletions lib/ansible/modules/cloud/docker/docker_host_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,40 +143,40 @@
returned: both on success and on error
type: bool

docker_host_facts:
host_facts:
description:
- Facts representing the basic state of the docker host. Matches the C(docker system info) output.
returned: always
type: dict
docker_volumes_list:
volumes:
description:
- List of dict objects containing the basic information about each volume.
Keys matches the C(docker volume ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(volumes) is C(yes)
type: list
docker_networks_list:
networks:
description:
- List of dict objects containing the basic information about each network.
Keys matches the C(docker network ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(networks) is C(yes)
type: list
docker_containers_list:
containers:
description:
- List of dict objects containing the basic information about each container.
Keys matches the C(docker container ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(containers) is C(yes)
type: list
docker_images_list:
images:
description:
- List of dict objects containing the basic information about each image.
Keys matches the C(docker image ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(images) is C(yes)
type: list
docker_disk_usage:
disk_usage:
description:
- Information on summary disk usage by images, containers and volumes on docker host
unless I(verbose_output=yes). See description for I(verbose_output).
Expand Down Expand Up @@ -209,14 +209,14 @@ def __init__(self, client, results):

listed_objects = ['volumes', 'networks', 'containers', 'images']

self.results['docker_host_facts'] = self.get_docker_host_facts()
self.results['host_facts'] = self.get_docker_host_facts()

if self.client.module.params['disk_usage']:
self.results['docker_disk_usage'] = self.get_docker_disk_usage_facts()
self.results['disk_usage'] = self.get_docker_disk_usage_facts()

for docker_object in listed_objects:
if self.client.module.params[docker_object]:
returned_name = "docker_" + docker_object + "_list"
returned_name = docker_object
filter_name = docker_object + "_filters"
filters = clean_dict_booleans_for_docker_api(client.module.params.get(filter_name))
self.results[returned_name] = self.get_docker_items_list(docker_object, filters)
Expand Down Expand Up @@ -314,7 +314,6 @@ def main():

results = dict(
changed=False,
docker_host_facts=[]
)

DockerHostManager(client, results)
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,11 +241,11 @@
'''

RETURN = '''
docker_network:
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. Note that the returned fact will be removed in Ansible 2.12.
are also accessible directly as C(docker_network). Note that the returned fact will be removed in Ansible 2.12.
returned: success
type: dict
sample: {}
Expand Down Expand Up @@ -575,7 +575,7 @@ def present(self):

network_facts = self.get_existing_network()
self.results['ansible_facts'] = {u'docker_network': network_facts}
self.results['docker_network'] = network_facts
self.results['network'] = network_facts

def absent(self):
self.diff_tracker.add('exists', parameter=False, active=self.existing_network is not None)
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_network_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@

- name: Print information about network
debug:
var: result.docker_network
var: result.network
when: result.exists
'''

Expand All @@ -67,7 +67,7 @@
type: bool
returned: always
sample: true
docker_network:
network:
description:
- Facts representing the current state of the network. Matches the docker inspection output.
- Will be C(None) if network does not exist.
Expand Down Expand Up @@ -122,7 +122,7 @@ def main():
client.module.exit_json(
changed=False,
exists=(True if network else False),
docker_network=network,
network=network,
)


Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_node_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
'''

RETURN = '''
nodes_facts:
nodes:
description:
- Facts representing the current state of the nodes. Matches the C(docker node inspect) output.
- Can contain multiple entries if more than one node provided in I(name), or I(name) is not provided.
Expand Down Expand Up @@ -136,11 +136,11 @@ def main():

client.fail_task_if_not_swarm_manager()

node = get_node_facts(client)
nodes = get_node_facts(client)

client.module.exit_json(
changed=False,
nodes_facts=node,
nodes=nodes,
)


Expand Down
10 changes: 5 additions & 5 deletions lib/ansible/modules/cloud/docker/docker_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,13 @@
'''

RETURN = '''
docker_stack_spec_diff:
stack_spec_diff:
description: |
dictionary containing the differences between the 'Spec' field
of the stack services before and after applying the new stack
definition.
sample: >
"docker_stack_specs_diff":
"stack_spec_diff":
{'test_stack_test_service': {u'TaskTemplate': {u'ContainerSpec': {delete: [u'Env']}}}}
returned: on change
type: dict
Expand Down Expand Up @@ -277,9 +277,9 @@ def main():
else:
module.exit_json(
changed=True,
docker_stack_spec_diff=json_diff(before_stack_services,
after_stack_services,
dump=True))
stack_spec_diff=json_diff(before_stack_services,
after_stack_services,
dump=True))

else:
if docker_stack_services(module, name):
Expand Down
15 changes: 7 additions & 8 deletions lib/ansible/modules/cloud/docker/docker_swarm_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
register: result

- debug:
var: result.docker_swarm_facts
var: result.swarm_facts
'''

RETURN = '''
Expand All @@ -144,27 +144,27 @@
returned: both on success and on error
type: bool

docker_swarm_facts:
swarm_facts:
description:
- Facts representing the basic state of the docker Swarm cluster.
- Contains tokens to connect to the Swarm
returned: always
type: dict
docker_nodes_list:
nodes:
description:
- List of dict objects containing the basic information about each volume.
Keys matches the C(docker node ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(nodes) is C(yes)
type: list
docker_services_list:
services:
description:
- List of dict objects containing the basic information about each volume.
Keys matches the C(docker service ls) output unless I(verbose_output=yes).
See description for I(verbose_output).
returned: When I(services) is C(yes)
type: list
docker_tasks_list:
tasks:
description:
- List of dict objects containing the basic information about each volume.
Keys matches the C(docker service ps) output unless I(verbose_output=yes).
Expand Down Expand Up @@ -200,11 +200,11 @@ def __init__(self, client, results):

self.client.fail_task_if_not_swarm_manager()

self.results['docker_swarm_facts'] = self.get_docker_swarm_facts()
self.results['swarm_facts'] = self.get_docker_swarm_facts()

for docker_object in listed_objects:
if self.client.module.params[docker_object]:
returned_name = "docker_" + docker_object + "_list"
returned_name = docker_object
filter_name = docker_object + "_filters"
filters = clean_dict_booleans_for_docker_api(client.module.params.get(filter_name))
self.results[returned_name] = self.get_docker_items_list(docker_object, filters)
Expand Down Expand Up @@ -334,7 +334,6 @@ def main():

results = dict(
changed=False,
docker_swarm_facts=[],
)

DockerSwarmManager(client, results)
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,11 @@
'''

RETURN = '''
docker_volume:
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. Note that the returned fact will be removed in Ansible 2.12.
are also accessible directly as C(docker_volume). Note that the returned fact will be removed in Ansible 2.12.
returned: success
type: dict
sample: {}
Expand Down Expand Up @@ -291,7 +291,7 @@ def present(self):

volume_facts = self.get_existing_volume()
self.results['ansible_facts'] = {u'docker_volume': volume_facts}
self.results['docker_volume'] = volume_facts
self.results['volume'] = volume_facts

def absent(self):
self.diff_tracker.add('exists', parameter=False, active=self.existing_volume is not None)
Expand Down
6 changes: 3 additions & 3 deletions lib/ansible/modules/cloud/docker/docker_volume_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

- name: Print information about volume
debug:
var: result.docker_volume
var: result.volume
when: result.exists
'''

Expand All @@ -63,7 +63,7 @@
type: bool
returned: always
sample: true
docker_volume:
volume:
description:
- Volume inspection results for the affected volume.
- Will be C(None) if volume does not exist.
Expand Down Expand Up @@ -115,7 +115,7 @@ def main():
client.module.exit_json(
changed=False,
exists=(True if volume else False),
docker_volume=volume,
volume=volume,
)


Expand Down