Repository: ansible/ansible

Issue:
detecting virtualization facts fails on OpenStack based Instances
##### ISSUE TYPE
- Bug Report
##### ANSIBLE VERSION

ansible 1.9.2  
ansible 2.0.1.0
##### OS / ENVIRONMENT

```
$ lsb_release -d                                               
Description:  Ubuntu 15.10
```
##### SUMMARY

ansible is not capable of properly detecting ansible_virtualization_role,  
when geathering facts of an OpenStack based instances
##### STEPS TO REPRODUCE

```
$ ansible 10.20.30.40 -u ubuntu -m setup -a "filter=ansible_virtualization_*"   
10.20.30.40 | SUCCESS => {                                                      
    "ansible_facts": {                                                          
        "ansible_virtualization_role": "host",                                  
        "ansible_virtualization_type": "kvm"                                    
    },                                                                          
    "changed": false                                                            
}
```
##### EXPECTED RESULTS

```
$ ansible 10.20.30.40 -u ubuntu -m setup -a "filter=ansible_virtualization_*"   
10.20.30.40 | SUCCESS => {                                                      
    "ansible_facts": {                                                          
        "ansible_virtualization_role": "guest",                                 
        "ansible_virtualization_type": "kvm"                                    
    },                                                                          
    "changed": false                                                            
}
```
##### ACTUAL RESULTS

see above
##### NOTE/FYI

```
$ ansible 10.20.30.40 -u ubuntu -m setup -a "filter=ansible_virtualization_*"   
10.20.30.40 | success >> {                                                      
    "ansible_facts": {                                                          
        "ansible_virtualization_role": "host",                                  
        "ansible_virtualization_type": "kvm"                                    
    },                                                                          
    "changed": false                                                            
}                                                                               
$ ansible 10.20.30.40 -u ubuntu -m modprobe -a "name=kvm_intel state=absent" -s 
10.20.30.40 | success >> {                                                      
    "changed": true,                                                            
    "failed": false,                                                            
    "name": "kvm_intel",                                                        
    "params": "",                                                               
    "state": "absent"                                                           
}                                                                               
$ ansible 10.20.30.40 -u ubuntu -m modprobe -a "name=kvm state=absent" -s       
10.20.30.40 | success >> {                                                      
    "changed": true,                                                            
    "failed": false,                                                            
    "name": "kvm",                                                              
    "params": "",                                                               
    "state": "absent"                                                           
}                                                                               
$ ansible 10.20.30.40 -u ubuntu -m setup -a "filter=ansible_virtualization_*"   
10.20.30.40 | success >> {                                                      
    "ansible_facts": {                                                          
        "ansible_virtualization_role": "NA",                                    
        "ansible_virtualization_type": "NA"                                     
    },                                                                          
    "changed": false                                                            
}
```



Discussion:

Resolving patch:
diff --git a/lib/ansible/module_utils/facts.py b/lib/ansible/module_utils/facts.py
--- a/lib/ansible/module_utils/facts.py
+++ b/lib/ansible/module_utils/facts.py
@@ -2740,6 +2740,11 @@ def get_virtual_facts(self):
             self.facts['virtualization_role'] = 'guest'
             return
 
+        if product_name == 'OpenStack Nova':
+            self.facts['virtualization_type'] = 'openstack'
+            self.facts['virtualization_role'] = 'guest'
+            return
+
         bios_vendor = get_file_content('/sys/devices/virtual/dmi/id/bios_vendor')
 
         if bios_vendor == 'Xen':
@@ -2775,6 +2780,11 @@ def get_virtual_facts(self):
             self.facts['virtualization_role'] = 'guest'
             return
 
+        if sys_vendor == 'OpenStack Foundation':
+            self.facts['virtualization_type'] = 'openstack'
+            self.facts['virtualization_role'] = 'guest'
+            return
+
         if os.path.exists('/proc/self/status'):
             for line in get_file_lines('/proc/self/status'):
                 if re.match('^VxID: \d+', line):


Test patch: