From 69e510e7672d556702f648fbcda1143c00fb781f Mon Sep 17 00:00:00 2001 From: Rick Elrod Date: Tue, 20 Oct 2020 10:39:13 -0500 Subject: [PATCH] [virt facts] recognize containerd as a container (#72210) Change: - containerd is now recognized as container tech Test Plan: - Tested with Docker inside Github Actions in a private repo: "ansible_virtualization_role": "guest", "ansible_virtualization_tech_guest": [ "containerd", "container", "VirtualPC" ], "ansible_virtualization_tech_host": [], "ansible_virtualization_type": "containerd", Tickets: - Fixes #66304 because this is what docker containers show up as in Github Actions. Signed-off-by: Rick Elrod --- changelogs/fragments/66304-facts_containerd.yml | 2 ++ lib/ansible/module_utils/facts/virtual/linux.py | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 changelogs/fragments/66304-facts_containerd.yml diff --git a/changelogs/fragments/66304-facts_containerd.yml b/changelogs/fragments/66304-facts_containerd.yml new file mode 100644 index 00000000000..5dc0aff7926 --- /dev/null +++ b/changelogs/fragments/66304-facts_containerd.yml @@ -0,0 +1,2 @@ +minor_changes: + - virtual facts - containerd cgroup is now recognized as container tech (https://github.com/ansible/ansible/issues/66304). diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py index f44c293c6c7..46a7cfaddc3 100644 --- a/lib/ansible/module_utils/facts/virtual/linux.py +++ b/lib/ansible/module_utils/facts/virtual/linux.py @@ -61,6 +61,12 @@ class LinuxVirtual(Virtual): virtual_facts['virtualization_type'] = 'lxc' virtual_facts['virtualization_role'] = 'guest' found_virt = True + if re.search('/system.slice/containerd.service', line): + guest_tech.add('containerd') + if not found_virt: + virtual_facts['virtualization_type'] = 'containerd' + virtual_facts['virtualization_role'] = 'guest' + found_virt = True # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs if os.path.exists('/proc/1/environ'): @@ -105,7 +111,7 @@ class LinuxVirtual(Virtual): found_virt = True # ensure 'container' guest_tech is appropriately set - if guest_tech.intersection(set(['docker', 'lxc', 'podman', 'openvz'])) or systemd_container: + if guest_tech.intersection(set(['docker', 'lxc', 'podman', 'openvz', 'containerd'])) or systemd_container: guest_tech.add('container') if os.path.exists("/proc/xen"):