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

url = 
"http://metadata.google.internal/computeMetadata/v1/instance/attributes/";
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

-- 
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 [email protected].
To post to this group, send email to [email protected].
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 via email to