Skip to content

Instantly share code, notes, and snippets.

@tgerla
Created July 17, 2015 13:58
Show Gist options
  • Save tgerla/38676b1feef835206672 to your computer and use it in GitHub Desktop.
Save tgerla/38676b1feef835206672 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
import sys
import os
from ansible.module_utils.basic import *
def main():
facts = {}
module = AnsibleModule(argument_spec={})
dmi_bin = module.get_bin_path('dmidecode')
if dmi_bin is not None:
(rc, out, err) = module.run_command('%s -s %s' % (dmi_bin, 'system-manufacturer'))
if rc == 0:
thisvalue = ''.join([ line for line in out.split('\n') if not line.startswith('#') ])
try:
json.dumps(thisvalue)
if "VMware" in thisvalue:
facts['ansible_virtualization_role'] = "guest"
facts['ansible_virtualization_type'] = "VMware"
except UnicodeDecodeError:
pass
facts_result = dict(changed=False, ansible_facts=facts)
module.exit_json(**facts_result)
if __name__ == '__main__':
main()
---
- hosts: vmware
tasks:
- name: load rhel5 virt facts
rhel5_vmware_facts:
sudo: true
- debug: var=ansible_virtualization_role
- debug: var=ansible_virtualization_type
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment