Skip to content

Commit

Permalink
Do not make ansible_connection unsafe.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixfontein committed Mar 13, 2024
1 parent 5435866 commit 9fbb008
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions plugins/inventory/docker_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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():
Expand All @@ -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

Expand All @@ -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
Expand Down

0 comments on commit 9fbb008

Please sign in to comment.