Use custom fact module

51 views
Skip to first unread message

Mark Olliver

unread,
Jul 1, 2014, 1:16:57 PM7/1/14
to ansible...@googlegroups.com
HI,

I have written a custom fact module to retrieve metadata from Google Compute Engine hosts. The script itself works fine and returns valid json however, I can not see how I call that within Ansible so that I can make use of the fact later.

My script is get_metadata.py
#!/usr/bin/env python
import urllib2
import sys
import json

headers = { "Metadata-Flavor" : "Google" }

metadata = ['dc']
content = {}

for x in range (0, len(metadata)):
    req = urllib2.Request(url + metadata[x], None, headers)
    try:
        response = urllib2.urlopen(req)
        content[metadata[x]] = (response.read())
    except urllib2.HTTPError, e:
        pass

result = '{ "ansible_facts": ' + json.dumps(content) + ' }'
print result


The ansible command I am using is: ansible-playbook -s -i plugins/inventory/gce.py -M /opt/ansible/modules/ deploy.yml
with my module stored in /opt/ansible/modules/get_metadata.py
Deploy.yml looks like this:
---

- hosts: manage-1
  tasks: []


  pre_tasks:
  - name: get meta data
  get_metadata:

  roles:
  - common


Any help would be appreciated.

Thanks

Mark

Michael DeHaan

unread,
Jul 1, 2014, 2:39:45 PM7/1/14
to ansible...@googlegroups.com
Hi, this is a topic for ansible-devel, can you please ask over there?   Thanks!




--
You received this message because you are subscribed to the Google Groups "Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ansible-proje...@googlegroups.com.
To post to this group, send email to ansible...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/e064db44-10e5-41cb-a391-91be55786a86%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages