We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Linux Vserver not detected properly
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and devel branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
lib/ansible/module_utils/facts/virtual/linux.py

##### ANSIBLE VERSION
ansible 2.4.3.0
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]

Also present in 'devel' branch.

##### OS / ENVIRONMENT
Host with Linux Vserver:
Linux FQDN 4.1.48-vs2.3.8.6-beng #1 SMP Sun Jan 14 14:33:48 GMT 2018 x86_64 GNU/Linux

##### SUMMARY
Ansible uses /proc/self/status to detect Linux Vserver with:

https://github.com/ansible/ansible/blob/6a223d55760dd21b5063ca2c8296f3ef57dd75e7/lib/ansible/module_utils/facts/virtual/linux.py#L157

This doesn't work on my system, the output of /proc/self/status contains:

```
Cpus_allowed:   ff
Cpus_allowed_list:      0-7
Mems_allowed:   00000000,00000001
Mems_allowed_list:      0
VxID:   40024
NxID:   40024
voluntary_ctxt_switches:        0
nonvoluntary_ctxt_switches:     1
```
There are three spaces between 'VxID:' and '40024', the regex only allows one.

Changing the code to:

`if re.match(r'^VxID:\s*\d+', line):`

Fixes this.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `lib/ansible/module_utils/facts/virtual/linux.py`
Content:
```
1 # This file is part of Ansible
2 #
3 # Ansible is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # Ansible is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with Ansible.  If not, see <http://www.gnu.org/licenses/>.
15 
16 from __future__ import (absolute_import, division, print_function)
17 __metaclass__ = type
18 
19 import glob
20 import os
21 import re
22 
23 from ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector
24 from ansible.module_utils.facts.utils import get_file_content, get_file_lines
25 
26 
27 class LinuxVirtual(Virtual):
28     """
29     This is a Linux-specific subclass of Virtual.  It defines
30     - virtualization_type
31     - virtualization_role
32     """
33     platform = 'Linux'
34 
35     # For more information, check: http://people.redhat.com/~rjones/virt-what/
36     def get_virtual_facts(self):
37         virtual_facts = {}
38         # lxc/docker
39         if os.path.exists('/proc/1/cgroup'):
40             for line in get_file_lines('/proc/1/cgroup'):
41                 if re.search(r'/docker(/|-[0-9a-f]+\.scope)', line):
42                     virtual_facts['virtualization_type'] = 'docker'
43                     virtual_facts['virtualization_role'] = 'guest'
44                     return virtual_facts
45                 if re.search('/lxc/', line) or re.search('/machine.slice/machine-lxc', line):
46                     virtual_facts['virtualization_type'] = 'lxc'
47                     virtual_facts['virtualization_role'] = 'guest'
48                     return virtual_facts
49 
50         # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs
51         if os.path.exists('/proc/1/environ'):
52             for line in get_file_lines('/proc/1/environ'):
53                 if re.search('container=lxc', line):
54                     virtual_facts['virtualization_type'] = 'lxc'
55                     virtual_facts['virtualization_role'] = 'guest'
56                     return virtual_facts
57 
58         if os.path.exists('/proc/vz') and not os.path.exists('/proc/lve'):
59             virtual_facts['virtualization_type'] = 'openvz'
60             if os.path.exists('/proc/bc'):
61                 virtual_facts['virtualization_role'] = 'host'
62             else:
63                 virtual_facts['virtualization_role'] = 'guest'
64             return virtual_facts
65 
66         systemd_container = get_file_content('/run/systemd/container')
67         if systemd_container:
68             virtual_facts['virtualization_type'] = systemd_container
69             virtual_facts['virtualization_role'] = 'guest'
70             return virtual_facts
71 
72         if os.path.exists("/proc/xen"):
73             virtual_facts['virtualization_type'] = 'xen'
74             virtual_facts['virtualization_role'] = 'guest'
75             try:
76                 for line in get_file_lines('/proc/xen/capabilities'):
77                     if "control_d" in line:
78                         virtual_facts['virtualization_role'] = 'host'
79             except IOError:
80                 pass
81             return virtual_facts
82 
83         product_name = get_file_content('/sys/devices/virtual/dmi/id/product_name')
84 
85         if product_name in ['KVM', 'Bochs']:
86             virtual_facts['virtualization_type'] = 'kvm'
87             virtual_facts['virtualization_role'] = 'guest'
88             return virtual_facts
89 
90         if product_name == 'RHEV Hypervisor':
91             virtual_facts['virtualization_type'] = 'RHEV'
92             virtual_facts['virtualization_role'] = 'guest'
93             return virtual_facts
94 
95         if product_name in ['VMware Virtual Platform', 'VMware7,1']:
96             virtual_facts['virtualization_type'] = 'VMware'
97             virtual_facts['virtualization_role'] = 'guest'
98             return virtual_facts
99 
100         if product_name in ['OpenStack Compute', 'OpenStack Nova']:
101             virtual_facts['virtualization_type'] = 'openstack'
102             virtual_facts['virtualization_role'] = 'guest'
103             return virtual_facts
104 
105         bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor')
106 
107         if bios_vendor == 'Xen':
108             virtual_facts['virtualization_type'] = 'xen'
109             virtual_facts['virtualization_role'] = 'guest'
110             return virtual_facts
111 
112         if bios_vendor == 'innotek GmbH':
113             virtual_facts['virtualization_type'] = 'virtualbox'
114             virtual_facts['virtualization_role'] = 'guest'
115             return virtual_facts
116 
117         if bios_vendor == 'Amazon EC2':
118             virtual_facts['virtualization_type'] = 'kvm'
119             virtual_facts['virtualization_role'] = 'guest'
120             return virtual_facts
121 
122         sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor')
123 
124         # FIXME: This does also match hyperv
125         if sys_vendor == 'Microsoft Corporation':
126             virtual_facts['virtualization_type'] = 'VirtualPC'
127             virtual_facts['virtualization_role'] = 'guest'
128             return virtual_facts
129 
130         if sys_vendor == 'Parallels Software International Inc.':
131             virtual_facts['virtualization_type'] = 'parallels'
132             virtual_facts['virtualization_role'] = 'guest'
133             return virtual_facts
134 
135         if sys_vendor == 'QEMU':
136             virtual_facts['virtualization_type'] = 'kvm'
137             virtual_facts['virtualization_role'] = 'guest'
138             return virtual_facts
139 
140         if sys_vendor == 'oVirt':
141             virtual_facts['virtualization_type'] = 'kvm'
142             virtual_facts['virtualization_role'] = 'guest'
143             return virtual_facts
144 
145         if sys_vendor == 'OpenStack Foundation':
146             virtual_facts['virtualization_type'] = 'openstack'
147             virtual_facts['virtualization_role'] = 'guest'
148             return virtual_facts
149 
150         if sys_vendor == 'Amazon EC2':
151             virtual_facts['virtualization_type'] = 'kvm'
152             virtual_facts['virtualization_role'] = 'guest'
153             return virtual_facts
154 
155         if os.path.exists('/proc/self/status'):
156             for line in get_file_lines('/proc/self/status'):
157                 if re.match(r'^VxID: \d+', line):
158                     virtual_facts['virtualization_type'] = 'linux_vserver'
159                     if re.match(r'^VxID: 0', line):
160                         virtual_facts['virtualization_role'] = 'host'
161                     else:
162                         virtual_facts['virtualization_role'] = 'guest'
163                     return virtual_facts
164 
165         if os.path.exists('/proc/cpuinfo'):
166             for line in get_file_lines('/proc/cpuinfo'):
167                 if re.match('^model name.*QEMU Virtual CPU', line):
168                     virtual_facts['virtualization_type'] = 'kvm'
169                 elif re.match('^vendor_id.*User Mode Linux', line):
170                     virtual_facts['virtualization_type'] = 'uml'
171                 elif re.match('^model name.*UML', line):
172                     virtual_facts['virtualization_type'] = 'uml'
173                 elif re.match('^machine.*CHRP IBM pSeries .emulated by qemu.', line):
174                     virtual_facts['virtualization_type'] = 'kvm'
175                 elif re.match('^vendor_id.*PowerVM Lx86', line):
176                     virtual_facts['virtualization_type'] = 'powervm_lx86'
177                 elif re.match('^vendor_id.*IBM/S390', line):
178                     virtual_facts['virtualization_type'] = 'PR/SM'
179                     lscpu = self.module.get_bin_path('lscpu')
180                     if lscpu:
181                         rc, out, err = self.module.run_command(["lscpu"])
182                         if rc == 0:
183                             for line in out.splitlines():
184                                 data = line.split(":", 1)
185                                 key = data[0].strip()
186                                 if key == 'Hypervisor':
187                                     virtual_facts['virtualization_type'] = data[1].strip()
188                     else:
189                         virtual_facts['virtualization_type'] = 'ibm_systemz'
190                 else:
191                     continue
192                 if virtual_facts['virtualization_type'] == 'PR/SM':
193                     virtual_facts['virtualization_role'] = 'LPAR'
194                 else:
195                     virtual_facts['virtualization_role'] = 'guest'
196                 return virtual_facts
197 
198         # Beware that we can have both kvm and virtualbox running on a single system
199         if os.path.exists("/proc/modules") and os.access('/proc/modules', os.R_OK):
200             modules = []
201             for line in get_file_lines("/proc/modules"):
202                 data = line.split(" ", 1)
203                 modules.append(data[0])
204 
205             if 'kvm' in modules:
206 
207                 if os.path.isdir('/rhev/'):
208 
209                     # Check whether this is a RHEV hypervisor (is vdsm running ?)
210                     for f in glob.glob('/proc/[0-9]*/comm'):
211                         try:
212                             if open(f).read().rstrip() == 'vdsm':
213                                 virtual_facts['virtualization_type'] = 'RHEV'
214                                 break
215                         except:
216                             pass
217                     else:
218                         virtual_facts['virtualization_type'] = 'kvm'
219 
220                 else:
221                     virtual_facts['virtualization_type'] = 'kvm'
222                     virtual_facts['virtualization_role'] = 'host'
223 
224                 return virtual_facts
225 
226             if 'vboxdrv' in modules:
227                 virtual_facts['virtualization_type'] = 'virtualbox'
228                 virtual_facts['virtualization_role'] = 'host'
229                 return virtual_facts
230 
231             if 'virtio' in modules:
232                 virtual_facts['virtualization_type'] = 'kvm'
233                 virtual_facts['virtualization_role'] = 'guest'
234                 return virtual_facts
235 
236         # In older Linux Kernel versions, /sys filesystem is not available
237         # dmidecode is the safest option to parse virtualization related values
238         dmi_bin = self.module.get_bin_path('dmidecode')
239         (rc, out, err) = self.module.run_command('%s -s system-product-name' % dmi_bin)
240         if rc == 0:
241             # Strip out commented lines (specific dmidecode output)
242             vendor_name = ''.join([line.strip() for line in out.splitlines() if not line.startswith('#')])
243             if vendor_name in ['VMware Virtual Platform', 'VMware7,1']:
244                 virtual_facts['virtualization_type'] = 'VMware'
245                 virtual_facts['virtualization_role'] = 'guest'
246 
247         # If none of the above matches, return 'NA' for virtualization_type
248         # and virtualization_role. This allows for proper grouping.
249         virtual_facts['virtualization_type'] = 'NA'
250         virtual_facts['virtualization_role'] = 'NA'
251 
252         return virtual_facts
253 
254 
255 class LinuxVirtualCollector(VirtualCollector):
256     _fact_class = LinuxVirtual
257     _platform = 'Linux'
258
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py
--- a/lib/ansible/module_utils/facts/virtual/linux.py
+++ b/lib/ansible/module_utils/facts/virtual/linux.py
@@ -154,9 +154,9 @@
 
         if os.path.exists('/proc/self/status'):
             for line in get_file_lines('/proc/self/status'):
-                if re.match(r'^VxID: \d+', line):
+                if re.match(r'^VxID:\s+\d+', line):
                     virtual_facts['virtualization_type'] = 'linux_vserver'
-                    if re.match(r'^VxID: 0', line):
+                    if re.match(r'^VxID:\s+0', line):
                         virtual_facts['virtualization_role'] = 'host'
                     else:
                         virtual_facts['virtualization_role'] = 'guest'
@@ -212,7 +212,7 @@
                             if open(f).read().rstrip() == 'vdsm':
                                 virtual_facts['virtualization_type'] = 'RHEV'
                                 break
-                        except:
+                        except Exception:
                             pass
                     else:
                         virtual_facts['virtualization_type'] = 'kvm'

{"golden_diff": "diff --git a/lib/ansible/module_utils/facts/virtual/linux.py b/lib/ansible/module_utils/facts/virtual/linux.py\n--- a/lib/ansible/module_utils/facts/virtual/linux.py\n+++ b/lib/ansible/module_utils/facts/virtual/linux.py\n@@ -154,9 +154,9 @@\n \n         if os.path.exists('/proc/self/status'):\n             for line in get_file_lines('/proc/self/status'):\n-                if re.match(r'^VxID: \\d+', line):\n+                if re.match(r'^VxID:\\s+\\d+', line):\n                     virtual_facts['virtualization_type'] = 'linux_vserver'\n-                    if re.match(r'^VxID: 0', line):\n+                    if re.match(r'^VxID:\\s+0', line):\n                         virtual_facts['virtualization_role'] = 'host'\n                     else:\n                         virtual_facts['virtualization_role'] = 'guest'\n@@ -212,7 +212,7 @@\n                             if open(f).read().rstrip() == 'vdsm':\n                                 virtual_facts['virtualization_type'] = 'RHEV'\n                                 break\n-                        except:\n+                        except Exception:\n                             pass\n                     else:\n                         virtual_facts['virtualization_type'] = 'kvm'\n", "issue": "Linux Vserver not detected properly\n<!---\r\nVerify first that your issue/request is not already reported on GitHub.\r\nAlso test if the latest release, and devel branch are affected too.\r\n-->\r\n\r\n##### ISSUE TYPE\r\n<!--- Pick one below and delete the rest -->\r\n - Bug Report\r\n\r\n##### COMPONENT NAME\r\nlib/ansible/module_utils/facts/virtual/linux.py\r\n\r\n##### ANSIBLE VERSION\r\nansible 2.4.3.0\r\n  config file = /etc/ansible/ansible.cfg\r\n  configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']\r\n  ansible python module location = /usr/lib/python2.7/dist-packages/ansible\r\n  executable location = /usr/bin/ansible\r\n  python version = 2.7.6 (default, Nov 23 2017, 15:49:48) [GCC 4.8.4]\r\n\r\nAlso present in 'devel' branch.\r\n\r\n##### OS / ENVIRONMENT\r\nHost with Linux Vserver:\r\nLinux FQDN 4.1.48-vs2.3.8.6-beng #1 SMP Sun Jan 14 14:33:48 GMT 2018 x86_64 GNU/Linux\r\n\r\n##### SUMMARY\r\nAnsible uses /proc/self/status to detect Linux Vserver with:\r\n\r\nhttps://github.com/ansible/ansible/blob/6a223d55760dd21b5063ca2c8296f3ef57dd75e7/lib/ansible/module_utils/facts/virtual/linux.py#L157\r\n\r\nThis doesn't work on my system, the output of /proc/self/status contains:\r\n\r\n```\r\nCpus_allowed:   ff\r\nCpus_allowed_list:      0-7\r\nMems_allowed:   00000000,00000001\r\nMems_allowed_list:      0\r\nVxID:   40024\r\nNxID:   40024\r\nvoluntary_ctxt_switches:        0\r\nnonvoluntary_ctxt_switches:     1\r\n```\r\nThere are three spaces between 'VxID:' and '40024', the regex only allows one.\r\n\r\nChanging the code to:\r\n\r\n`if re.match(r'^VxID:\\s*\\d+', line):`\r\n\r\nFixes this.\n", "before_files": [{"content": "# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nimport glob\nimport os\nimport re\n\nfrom ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector\nfrom ansible.module_utils.facts.utils import get_file_content, get_file_lines\n\n\nclass LinuxVirtual(Virtual):\n    \"\"\"\n    This is a Linux-specific subclass of Virtual.  It defines\n    - virtualization_type\n    - virtualization_role\n    \"\"\"\n    platform = 'Linux'\n\n    # For more information, check: http://people.redhat.com/~rjones/virt-what/\n    def get_virtual_facts(self):\n        virtual_facts = {}\n        # lxc/docker\n        if os.path.exists('/proc/1/cgroup'):\n            for line in get_file_lines('/proc/1/cgroup'):\n                if re.search(r'/docker(/|-[0-9a-f]+\\.scope)', line):\n                    virtual_facts['virtualization_type'] = 'docker'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n                if re.search('/lxc/', line) or re.search('/machine.slice/machine-lxc', line):\n                    virtual_facts['virtualization_type'] = 'lxc'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs\n        if os.path.exists('/proc/1/environ'):\n            for line in get_file_lines('/proc/1/environ'):\n                if re.search('container=lxc', line):\n                    virtual_facts['virtualization_type'] = 'lxc'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        if os.path.exists('/proc/vz') and not os.path.exists('/proc/lve'):\n            virtual_facts['virtualization_type'] = 'openvz'\n            if os.path.exists('/proc/bc'):\n                virtual_facts['virtualization_role'] = 'host'\n            else:\n                virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        systemd_container = get_file_content('/run/systemd/container')\n        if systemd_container:\n            virtual_facts['virtualization_type'] = systemd_container\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if os.path.exists(\"/proc/xen\"):\n            virtual_facts['virtualization_type'] = 'xen'\n            virtual_facts['virtualization_role'] = 'guest'\n            try:\n                for line in get_file_lines('/proc/xen/capabilities'):\n                    if \"control_d\" in line:\n                        virtual_facts['virtualization_role'] = 'host'\n            except IOError:\n                pass\n            return virtual_facts\n\n        product_name = get_file_content('/sys/devices/virtual/dmi/id/product_name')\n\n        if product_name in ['KVM', 'Bochs']:\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name == 'RHEV Hypervisor':\n            virtual_facts['virtualization_type'] = 'RHEV'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name in ['VMware Virtual Platform', 'VMware7,1']:\n            virtual_facts['virtualization_type'] = 'VMware'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name in ['OpenStack Compute', 'OpenStack Nova']:\n            virtual_facts['virtualization_type'] = 'openstack'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor')\n\n        if bios_vendor == 'Xen':\n            virtual_facts['virtualization_type'] = 'xen'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if bios_vendor == 'innotek GmbH':\n            virtual_facts['virtualization_type'] = 'virtualbox'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if bios_vendor == 'Amazon EC2':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor')\n\n        # FIXME: This does also match hyperv\n        if sys_vendor == 'Microsoft Corporation':\n            virtual_facts['virtualization_type'] = 'VirtualPC'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'Parallels Software International Inc.':\n            virtual_facts['virtualization_type'] = 'parallels'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'QEMU':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'oVirt':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'OpenStack Foundation':\n            virtual_facts['virtualization_type'] = 'openstack'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'Amazon EC2':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if os.path.exists('/proc/self/status'):\n            for line in get_file_lines('/proc/self/status'):\n                if re.match(r'^VxID: \\d+', line):\n                    virtual_facts['virtualization_type'] = 'linux_vserver'\n                    if re.match(r'^VxID: 0', line):\n                        virtual_facts['virtualization_role'] = 'host'\n                    else:\n                        virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        if os.path.exists('/proc/cpuinfo'):\n            for line in get_file_lines('/proc/cpuinfo'):\n                if re.match('^model name.*QEMU Virtual CPU', line):\n                    virtual_facts['virtualization_type'] = 'kvm'\n                elif re.match('^vendor_id.*User Mode Linux', line):\n                    virtual_facts['virtualization_type'] = 'uml'\n                elif re.match('^model name.*UML', line):\n                    virtual_facts['virtualization_type'] = 'uml'\n                elif re.match('^machine.*CHRP IBM pSeries .emulated by qemu.', line):\n                    virtual_facts['virtualization_type'] = 'kvm'\n                elif re.match('^vendor_id.*PowerVM Lx86', line):\n                    virtual_facts['virtualization_type'] = 'powervm_lx86'\n                elif re.match('^vendor_id.*IBM/S390', line):\n                    virtual_facts['virtualization_type'] = 'PR/SM'\n                    lscpu = self.module.get_bin_path('lscpu')\n                    if lscpu:\n                        rc, out, err = self.module.run_command([\"lscpu\"])\n                        if rc == 0:\n                            for line in out.splitlines():\n                                data = line.split(\":\", 1)\n                                key = data[0].strip()\n                                if key == 'Hypervisor':\n                                    virtual_facts['virtualization_type'] = data[1].strip()\n                    else:\n                        virtual_facts['virtualization_type'] = 'ibm_systemz'\n                else:\n                    continue\n                if virtual_facts['virtualization_type'] == 'PR/SM':\n                    virtual_facts['virtualization_role'] = 'LPAR'\n                else:\n                    virtual_facts['virtualization_role'] = 'guest'\n                return virtual_facts\n\n        # Beware that we can have both kvm and virtualbox running on a single system\n        if os.path.exists(\"/proc/modules\") and os.access('/proc/modules', os.R_OK):\n            modules = []\n            for line in get_file_lines(\"/proc/modules\"):\n                data = line.split(\" \", 1)\n                modules.append(data[0])\n\n            if 'kvm' in modules:\n\n                if os.path.isdir('/rhev/'):\n\n                    # Check whether this is a RHEV hypervisor (is vdsm running ?)\n                    for f in glob.glob('/proc/[0-9]*/comm'):\n                        try:\n                            if open(f).read().rstrip() == 'vdsm':\n                                virtual_facts['virtualization_type'] = 'RHEV'\n                                break\n                        except:\n                            pass\n                    else:\n                        virtual_facts['virtualization_type'] = 'kvm'\n\n                else:\n                    virtual_facts['virtualization_type'] = 'kvm'\n                    virtual_facts['virtualization_role'] = 'host'\n\n                return virtual_facts\n\n            if 'vboxdrv' in modules:\n                virtual_facts['virtualization_type'] = 'virtualbox'\n                virtual_facts['virtualization_role'] = 'host'\n                return virtual_facts\n\n            if 'virtio' in modules:\n                virtual_facts['virtualization_type'] = 'kvm'\n                virtual_facts['virtualization_role'] = 'guest'\n                return virtual_facts\n\n        # In older Linux Kernel versions, /sys filesystem is not available\n        # dmidecode is the safest option to parse virtualization related values\n        dmi_bin = self.module.get_bin_path('dmidecode')\n        (rc, out, err) = self.module.run_command('%s -s system-product-name' % dmi_bin)\n        if rc == 0:\n            # Strip out commented lines (specific dmidecode output)\n            vendor_name = ''.join([line.strip() for line in out.splitlines() if not line.startswith('#')])\n            if vendor_name in ['VMware Virtual Platform', 'VMware7,1']:\n                virtual_facts['virtualization_type'] = 'VMware'\n                virtual_facts['virtualization_role'] = 'guest'\n\n        # If none of the above matches, return 'NA' for virtualization_type\n        # and virtualization_role. This allows for proper grouping.\n        virtual_facts['virtualization_type'] = 'NA'\n        virtual_facts['virtualization_role'] = 'NA'\n\n        return virtual_facts\n\n\nclass LinuxVirtualCollector(VirtualCollector):\n    _fact_class = LinuxVirtual\n    _platform = 'Linux'\n", "path": "lib/ansible/module_utils/facts/virtual/linux.py"}], "after_files": [{"content": "# This file is part of Ansible\n#\n# Ansible is free software: you can redistribute it and/or modify\n# it under the terms of the GNU General Public License as published by\n# the Free Software Foundation, either version 3 of the License, or\n# (at your option) any later version.\n#\n# Ansible is distributed in the hope that it will be useful,\n# but WITHOUT ANY WARRANTY; without even the implied warranty of\n# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n# GNU General Public License for more details.\n#\n# You should have received a copy of the GNU General Public License\n# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.\n\nfrom __future__ import (absolute_import, division, print_function)\n__metaclass__ = type\n\nimport glob\nimport os\nimport re\n\nfrom ansible.module_utils.facts.virtual.base import Virtual, VirtualCollector\nfrom ansible.module_utils.facts.utils import get_file_content, get_file_lines\n\n\nclass LinuxVirtual(Virtual):\n    \"\"\"\n    This is a Linux-specific subclass of Virtual.  It defines\n    - virtualization_type\n    - virtualization_role\n    \"\"\"\n    platform = 'Linux'\n\n    # For more information, check: http://people.redhat.com/~rjones/virt-what/\n    def get_virtual_facts(self):\n        virtual_facts = {}\n        # lxc/docker\n        if os.path.exists('/proc/1/cgroup'):\n            for line in get_file_lines('/proc/1/cgroup'):\n                if re.search(r'/docker(/|-[0-9a-f]+\\.scope)', line):\n                    virtual_facts['virtualization_type'] = 'docker'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n                if re.search('/lxc/', line) or re.search('/machine.slice/machine-lxc', line):\n                    virtual_facts['virtualization_type'] = 'lxc'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        # lxc does not always appear in cgroups anymore but sets 'container=lxc' environment var, requires root privs\n        if os.path.exists('/proc/1/environ'):\n            for line in get_file_lines('/proc/1/environ'):\n                if re.search('container=lxc', line):\n                    virtual_facts['virtualization_type'] = 'lxc'\n                    virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        if os.path.exists('/proc/vz') and not os.path.exists('/proc/lve'):\n            virtual_facts['virtualization_type'] = 'openvz'\n            if os.path.exists('/proc/bc'):\n                virtual_facts['virtualization_role'] = 'host'\n            else:\n                virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        systemd_container = get_file_content('/run/systemd/container')\n        if systemd_container:\n            virtual_facts['virtualization_type'] = systemd_container\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if os.path.exists(\"/proc/xen\"):\n            virtual_facts['virtualization_type'] = 'xen'\n            virtual_facts['virtualization_role'] = 'guest'\n            try:\n                for line in get_file_lines('/proc/xen/capabilities'):\n                    if \"control_d\" in line:\n                        virtual_facts['virtualization_role'] = 'host'\n            except IOError:\n                pass\n            return virtual_facts\n\n        product_name = get_file_content('/sys/devices/virtual/dmi/id/product_name')\n\n        if product_name in ['KVM', 'Bochs']:\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name == 'RHEV Hypervisor':\n            virtual_facts['virtualization_type'] = 'RHEV'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name in ['VMware Virtual Platform', 'VMware7,1']:\n            virtual_facts['virtualization_type'] = 'VMware'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if product_name in ['OpenStack Compute', 'OpenStack Nova']:\n            virtual_facts['virtualization_type'] = 'openstack'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor')\n\n        if bios_vendor == 'Xen':\n            virtual_facts['virtualization_type'] = 'xen'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if bios_vendor == 'innotek GmbH':\n            virtual_facts['virtualization_type'] = 'virtualbox'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if bios_vendor == 'Amazon EC2':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor')\n\n        # FIXME: This does also match hyperv\n        if sys_vendor == 'Microsoft Corporation':\n            virtual_facts['virtualization_type'] = 'VirtualPC'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'Parallels Software International Inc.':\n            virtual_facts['virtualization_type'] = 'parallels'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'QEMU':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'oVirt':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'OpenStack Foundation':\n            virtual_facts['virtualization_type'] = 'openstack'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if sys_vendor == 'Amazon EC2':\n            virtual_facts['virtualization_type'] = 'kvm'\n            virtual_facts['virtualization_role'] = 'guest'\n            return virtual_facts\n\n        if os.path.exists('/proc/self/status'):\n            for line in get_file_lines('/proc/self/status'):\n                if re.match(r'^VxID:\\s+\\d+', line):\n                    virtual_facts['virtualization_type'] = 'linux_vserver'\n                    if re.match(r'^VxID:\\s+0', line):\n                        virtual_facts['virtualization_role'] = 'host'\n                    else:\n                        virtual_facts['virtualization_role'] = 'guest'\n                    return virtual_facts\n\n        if os.path.exists('/proc/cpuinfo'):\n            for line in get_file_lines('/proc/cpuinfo'):\n                if re.match('^model name.*QEMU Virtual CPU', line):\n                    virtual_facts['virtualization_type'] = 'kvm'\n                elif re.match('^vendor_id.*User Mode Linux', line):\n                    virtual_facts['virtualization_type'] = 'uml'\n                elif re.match('^model name.*UML', line):\n                    virtual_facts['virtualization_type'] = 'uml'\n                elif re.match('^machine.*CHRP IBM pSeries .emulated by qemu.', line):\n                    virtual_facts['virtualization_type'] = 'kvm'\n                elif re.match('^vendor_id.*PowerVM Lx86', line):\n                    virtual_facts['virtualization_type'] = 'powervm_lx86'\n                elif re.match('^vendor_id.*IBM/S390', line):\n                    virtual_facts['virtualization_type'] = 'PR/SM'\n                    lscpu = self.module.get_bin_path('lscpu')\n                    if lscpu:\n                        rc, out, err = self.module.run_command([\"lscpu\"])\n                        if rc == 0:\n                            for line in out.splitlines():\n                                data = line.split(\":\", 1)\n                                key = data[0].strip()\n                                if key == 'Hypervisor':\n                                    virtual_facts['virtualization_type'] = data[1].strip()\n                    else:\n                        virtual_facts['virtualization_type'] = 'ibm_systemz'\n                else:\n                    continue\n                if virtual_facts['virtualization_type'] == 'PR/SM':\n                    virtual_facts['virtualization_role'] = 'LPAR'\n                else:\n                    virtual_facts['virtualization_role'] = 'guest'\n                return virtual_facts\n\n        # Beware that we can have both kvm and virtualbox running on a single system\n        if os.path.exists(\"/proc/modules\") and os.access('/proc/modules', os.R_OK):\n            modules = []\n            for line in get_file_lines(\"/proc/modules\"):\n                data = line.split(\" \", 1)\n                modules.append(data[0])\n\n            if 'kvm' in modules:\n\n                if os.path.isdir('/rhev/'):\n\n                    # Check whether this is a RHEV hypervisor (is vdsm running ?)\n                    for f in glob.glob('/proc/[0-9]*/comm'):\n                        try:\n                            if open(f).read().rstrip() == 'vdsm':\n                                virtual_facts['virtualization_type'] = 'RHEV'\n                                break\n                        except Exception:\n                            pass\n                    else:\n                        virtual_facts['virtualization_type'] = 'kvm'\n\n                else:\n                    virtual_facts['virtualization_type'] = 'kvm'\n                    virtual_facts['virtualization_role'] = 'host'\n\n                return virtual_facts\n\n            if 'vboxdrv' in modules:\n                virtual_facts['virtualization_type'] = 'virtualbox'\n                virtual_facts['virtualization_role'] = 'host'\n                return virtual_facts\n\n            if 'virtio' in modules:\n                virtual_facts['virtualization_type'] = 'kvm'\n                virtual_facts['virtualization_role'] = 'guest'\n                return virtual_facts\n\n        # In older Linux Kernel versions, /sys filesystem is not available\n        # dmidecode is the safest option to parse virtualization related values\n        dmi_bin = self.module.get_bin_path('dmidecode')\n        (rc, out, err) = self.module.run_command('%s -s system-product-name' % dmi_bin)\n        if rc == 0:\n            # Strip out commented lines (specific dmidecode output)\n            vendor_name = ''.join([line.strip() for line in out.splitlines() if not line.startswith('#')])\n            if vendor_name in ['VMware Virtual Platform', 'VMware7,1']:\n                virtual_facts['virtualization_type'] = 'VMware'\n                virtual_facts['virtualization_role'] = 'guest'\n\n        # If none of the above matches, return 'NA' for virtualization_type\n        # and virtualization_role. This allows for proper grouping.\n        virtual_facts['virtualization_type'] = 'NA'\n        virtual_facts['virtualization_role'] = 'NA'\n\n        return virtual_facts\n\n\nclass LinuxVirtualCollector(VirtualCollector):\n    _fact_class = LinuxVirtual\n    _platform = 'Linux'\n", "path": "lib/ansible/module_utils/facts/virtual/linux.py"}]}