From 54c530a3ee92165c985ffba66b671dd579c9d0b6 Mon Sep 17 00:00:00 2001 From: Brian Coca Date: Mon, 22 Aug 2016 08:44:10 -0400 Subject: [PATCH] more ways to detect lxc thanks to @wAmpire for new method and pointing out limitations of existing --- lib/ansible/module_utils/facts.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py index 34950a209f1..820e99857cf 100644 --- a/lib/ansible/module_utils/facts.py +++ b/lib/ansible/module_utils/facts.py @@ -2973,19 +2973,19 @@ class LinuxVirtual(Virtual): # For more information, check: http://people.redhat.com/~rjones/virt-what/ def get_virtual_facts(self): - # old lxc/docker + # lxc/docker if os.path.exists('/proc/1/cgroup'): for line in get_file_lines('/proc/1/cgroup'): if re.search(r'/docker(/|-[0-9a-f]+\.scope)', line): self.facts['virtualization_type'] = 'docker' self.facts['virtualization_role'] = 'guest' return - if re.search('/lxc/', line): + if re.search('/lxc/', line) or re.search('/machine.slice/machine-lxc', line): self.facts['virtualization_type'] = 'lxc' self.facts['virtualization_role'] = 'guest' return - # newer lxc does not appear in cgroups anymore but sets 'container=lxc' environment var + # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs if os.path.exists('/proc/1/environ'): for line in get_file_lines('/proc/1/environ'): if re.search('container=lxc', line):