Repository: ansible/ansible

Issue:
ansible_virtualization_role incorrectly set to host on DigitalOcean droplets
<!---
Verify first that your issue/request is not already reported on GitHub.
THIS FORM WILL BE READ BY A MACHINE, COMPLETE ALL SECTIONS AS DESCRIBED.
Also test if the latest release, and devel branch are affected too.
ALWAYS add information AFTER (OUTSIDE) these html comments.
Otherwise it may end up being automatically closed by our bot. -->

##### SUMMARY
<!--- Explain the problem briefly -->
`ansible_virtualization_role` is incorrectly set to `host` on DigitalOcean droplets - it should be `guest`.

##### ISSUE TYPE
 - Bug Report

##### COMPONENT NAME
<!--- Insert, BELOW THIS COMMENT, the 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-->
core

##### ANSIBLE VERSION
<!--- Paste, BELOW THIS COMMENT, verbatim output from "ansible --version" between quotes below -->
```
ansible 2.5.4
  config file = /Users/tomkins/Admin/blazingfast.net/ansible.cfg
  configured module search path = ['/Users/tomkins/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/tomkins/.virtualenvs/blazingfast/lib/python3.5/site-packages/ansible
  executable location = /Users/tomkins/.virtualenvs/blazingfast/bin/ansible
  python version = 3.5.5 (default, Mar 29 2018, 16:22:58) [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.39.2)]
```

##### CONFIGURATION
<!--- If using Ansible 2.4 or above, paste, BELOW THIS COMMENT, 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).-->
N/A

##### OS / ENVIRONMENT
<!--- Mention, BELOW THIS COMMENT, 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.-->
Target server:

```
root@ubuntu-s-1vcpu-1gb-lon1-01:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 16.04.4 LTS
Release:	16.04
Codename:	xenial
```

##### 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. -->

<!--- Paste example playbooks or commands between quotes below -->
```console
$ ansible -m setup -a "filter=ansible_virtualization_*" ubuntu-s-1vcpu-1gb-lon1-01
ubuntu-s-1vcpu-1gb-lon1-01 | SUCCESS => {
    "ansible_facts": {
        "ansible_virtualization_role": "host",
        "ansible_virtualization_type": "kvm"
    },
    "changed": false
}
```

<!--- You can also paste gist.github.com links for larger files -->

##### EXPECTED RESULTS
<!--- What did you expect to happen when running the steps above? -->
`ansible_virtualization_role` should be set to `guest`

##### ACTUAL RESULTS
<!--- What actually happened? If possible run with extra verbosity (-vvvv) -->
`ansible_virtualization_role` was set to `host`

DigitalOcean droplets have the following DMI files available:

```console
root@ubuntu-s-1vcpu-1gb-lon1-01:~# cat /sys/devices/virtual/dmi/id/product_name
Droplet
root@ubuntu-s-1vcpu-1gb-lon1-01:~# cat /sys/devices/virtual/dmi/id/bios_vendor
DigitalOcean
root@ubuntu-s-1vcpu-1gb-lon1-01:~# cat /sys/devices/virtual/dmi/id/sys_vendor
DigitalOcean
```

But currently ansible isn't picking up any of them.


Discussion:

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
@@ -111,13 +111,13 @@ def get_virtual_facts(self):
             virtual_facts['virtualization_type'] = 'virtualbox'
             return virtual_facts
 
-        if bios_vendor in ('Amazon EC2', 'Hetzner'):
+        if bios_vendor in ('Amazon EC2', 'DigitalOcean', 'Hetzner'):
             virtual_facts['virtualization_type'] = 'kvm'
             return virtual_facts
 
         sys_vendor = get_file_content('/sys/devices/virtual/dmi/id/sys_vendor')
 
-        KVM_SYS_VENDORS = ('QEMU', 'oVirt', 'Amazon EC2', 'Google', 'Scaleway')
+        KVM_SYS_VENDORS = ('QEMU', 'oVirt', 'Amazon EC2', 'DigitalOcean', 'Google', 'Scaleway')
         if sys_vendor in KVM_SYS_VENDORS:
             virtual_facts['virtualization_type'] = 'kvm'
             return virtual_facts


Test patch: