Skip to content

Commit

Permalink
Improve container detection. (#522) (#523)
Browse files Browse the repository at this point in the history
(cherry picked from commit e87b327)
  • Loading branch information
felixfontein authored Dec 6, 2022
1 parent 32838bf commit 8811d9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 2 additions & 0 deletions changelogs/fragments/522-current-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- "current_container_facts - make container detection work better in more cases (https://github.com/ansible-collections/community.docker/pull/522)."
5 changes: 4 additions & 1 deletion plugins/modules/current_container_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,13 @@ def main():
with open(mountinfo_path, 'rb') as f:
contents = f.read().decode('utf-8')

# As to why this works, see the explanations by Matt Clay in
# https://github.com/ansible/ansible/blob/80d2f8da02052f64396da6b8caaf820eedbf18e2/test/lib/ansible_test/_internal/docker_util.py#L571-L610

for line in contents.splitlines():
parts = line.split()
if len(parts) >= 5 and parts[4] == '/etc/hostname':
m = re.match('.*/docker/containers/([a-f0-9]+)/hostname', parts[3])
m = re.match('.*/([a-f0-9]{64})/hostname$', parts[3])
if m:
container_id = m.group(1)
container_type = 'docker'
Expand Down

0 comments on commit 8811d9b

Please sign in to comment.