From 9fbb008918889b9a2c27d579c3939369fa90cc56 Mon Sep 17 00:00:00 2001 From: Felix Fontein Date: Wed, 13 Mar 2024 20:04:53 +0100 Subject: [PATCH] Do not make ansible_connection unsafe. --- plugins/inventory/docker_containers.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/inventory/docker_containers.py b/plugins/inventory/docker_containers.py index 8f8663617..75b49ff92 100644 --- a/plugins/inventory/docker_containers.py +++ b/plugins/inventory/docker_containers.py @@ -275,6 +275,7 @@ def _populate(self, client): if add_legacy_groups: groups.append('service_{0}'.format(service_name)) + ansible_connection = None if connection_type == 'ssh': # Figure out ssh IP and Port try: @@ -297,14 +298,14 @@ def _populate(self, client): elif connection_type == 'docker-cli': facts.update(dict( ansible_host=full_name, - ansible_connection='community.docker.docker', )) + ansible_connection = 'community.docker.docker' elif connection_type == 'docker-api': facts.update(dict( ansible_host=full_name, - ansible_connection='community.docker.docker_api', )) facts.update(extra_facts) + ansible_connection = 'community.docker.docker_api' full_facts.update(facts) for key, value in inspect.items(): @@ -313,6 +314,11 @@ def _populate(self, client): full_facts = make_unsafe(full_facts) + if ansible_connection: + for d in (facts, full_facts): + if 'ansible_connection' not in d: + d['ansible_connection'] = ansible_connection + if not filter_host(self, name, full_facts, filters): continue @@ -325,7 +331,7 @@ def _populate(self, client): self.inventory.add_host(name, group=group) for key, value in facts.items(): - self.inventory.set_variable(name, key, make_unsafe(value)) + self.inventory.set_variable(name, key, value) # Use constructed if applicable # Composed variables