Repository: ansible/ansible

Issue:
ansible_virtualization_type and ansible_virtualization_role not recognized for Amazon EC2 C5 Instances
<!---
Verify first that your issue/request is not already reported on GitHub.
Also test if the latest release, and master branch are affected too.
-->

##### ISSUE TYPE
<!--- Pick one below and delete the rest -->
 - Bug Report

##### COMPONENT NAME
<!---
Name of the module, plugin, task or feature
Do not include extra details here, e.g. "vyos_command" not "the network module vyos_command" or the full path
-->
lib/ansible/module_utils/facts/virtual/linux.py

##### ANSIBLE VERSION
<!--- Paste verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.0 (devel fb18338cdc) last updated 2018/01/18 11:02:22 (GMT -400)
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/rteague/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /home/rteague/git/clusters/aws-c1/ansible/lib/ansible
  executable location = /home/rteague/git/clusters/aws-c1/ansible/bin/ansible
  python version = 2.7.14 (default, Jan 11 2018, 14:45:11) [GCC 7.2.1 20170915 (Red Hat 7.2.1-2)]

```

##### CONFIGURATION
<!---
If using Ansible 2.4 or above, paste the results of "ansible-config dump --only-changed"
Otherwise, mention any settings you have changed/added/removed in ansible.cfg
(or using the ANSIBLE_* environment variables).
-->
```
$ ansible-config dump --only-changed
(no output)
```

##### OS / ENVIRONMENT
<!---
Mention the OS you are running Ansible from, and the OS you are
managing, or say "N/A" for anything that is not platform-specific.
Also mention the specific version of what you are trying to control,
e.g. if this is a network bug the version of firmware on the network device.
-->
N/A

##### SUMMARY
<!--- Explain the problem briefly -->
Amazon EC2 C5 instances are not properly recognized due to a change in bios_vendor/sys_vendor identifier.

##### STEPS TO REPRODUCE
<!---
For bugs, show exactly how to reproduce the problem, using a minimal test-case.
For new features, show how the feature would be used.
-->
On a C5 instance:
```
$ ansible -m setup all -i /tmp/c5_host |grep "virtualization"
        "ansible_virtualization_role": "NA", 
        "ansible_virtualization_type": "NA", 
```



##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
Expected _role and _type to be properly populated.

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->

<!--- Paste verbatim command output between quotes below -->
```
Checked on the EC2 C5 instance:
# cat /sys/devices/virtual/dmi/id/bios_vendor
Amazon EC2
# cat /sys/devices/virtual/dmi/id/sys_vendor
Amazon EC2
# cat /sys/devices/virtual/dmi/id/product_name
c5.large

Checking on a normal EC2 instance:
# cat /sys/devices/virtual/dmi/id/bios_vendor
Xen
# cat /sys/devices/virtual/dmi/id/sys_vendor
Xen
# cat /sys/devices/virtual/dmi/id/product_name
HVM domU
```
Please see related bug: https://bugzilla.redhat.com/show_bug.cgi?id=1533099


Discussion:
/cc @maxamillion 

Resolving patch:
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
@@ -114,6 +114,11 @@ def get_virtual_facts(self):
             virtual_facts['virtualization_role'] = 'guest'
             return virtual_facts
 
+        if bios_vendor == 'Amazon EC2':
+            virtual_facts['virtualization_type'] = 'kvm'
+            virtual_facts['virtualization_role'] = 'guest'
+            return virtual_facts
+
         sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor')
 
         # FIXME: This does also match hyperv
@@ -142,6 +147,11 @@ def get_virtual_facts(self):
             virtual_facts['virtualization_role'] = 'guest'
             return virtual_facts
 
+        if sys_vendor == 'Amazon EC2':
+            virtual_facts['virtualization_type'] = 'kvm'
+            virtual_facts['virtualization_role'] = 'guest'
+            return virtual_facts
+
         if os.path.exists('/proc/self/status'):
             for line in get_file_lines('/proc/self/status'):
                 if re.match(r'^VxID: \d+', line):


Test patch: