Skip to content

Instantly share code, notes, and snippets.

@jcpowermac
Created January 25, 2015 04:51
Show Gist options
  • Select an option

  • Save jcpowermac/841cf6a5b1b0e1e1a3b5 to your computer and use it in GitHub Desktop.

Select an option

Save jcpowermac/841cf6a5b1b0e1e1a3b5 to your computer and use it in GitHub Desktop.
import requests
def create_argument_spec(base_url, model):
url = "%s/model/templates/%s" % (base_url, model)
argument_spec = dict()
argument_spec.update(
base_url=dict(required=True),
model=dict(required=True))
req = requests.get(url)
if req.status_code != 200:
exit(1)
template = req.json()
count = 0
for req_metadata in template['response']['@req_metadata_hash']:
print req_metadata[1:]
print template['response']['@req_metadata_hash'][req_metadata]['required']
count += 1
argument_spec.update({
req_metadata[1:]: dict(
{'required': template['response']['@req_metadata_hash'][req_metadata]['required']}
)})
return argument_spec
from ansible.module_utils.basic import *
def main():
# So we are going to cheat a little. In order to use the AnsibleModule we will peek at
# at the input to determine the basic configuration, model template being used and the URI
# of the hanlon server.
for arg in sys.argv:
if arg.find("base_url") != -1:
base_url = arg.split('=')[1]
elif arg.find("model") != -1:
model = arg.split('=')[1]
# need check to make sure values are filled in
argument_spec = create_argument_spec(base_url, model)
module = AnsibleModule(argument_spec=argument_spec)
module.exit_json(changed=True, something_else=12345)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment