Created
July 17, 2015 13:58
-
-
Save tgerla/38676b1feef835206672 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- | |
- 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