[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 <rick@elrod.me>
This commit is contained in:
Rick Elrod 2020-10-20 10:39:13 -05:00 committed by GitHub
parent afba5c2852
commit 69e510e767
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- virtual facts - containerd cgroup is now recognized as container tech (https://github.com/ansible/ansible/issues/66304).

View file

@ -61,6 +61,12 @@ class LinuxVirtual(Virtual):
virtual_facts['virtualization_type'] = 'lxc' virtual_facts['virtualization_type'] = 'lxc'
virtual_facts['virtualization_role'] = 'guest' virtual_facts['virtualization_role'] = 'guest'
found_virt = True 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 # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs
if os.path.exists('/proc/1/environ'): if os.path.exists('/proc/1/environ'):
@ -105,7 +111,7 @@ class LinuxVirtual(Virtual):
found_virt = True found_virt = True
# ensure 'container' guest_tech is appropriately set # 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') guest_tech.add('container')
if os.path.exists("/proc/xen"): if os.path.exists("/proc/xen"):