-
-
Save jpmens/4b67010fc6cbe9ff42bc to your computer and use it in GitHub Desktop.
Ansible complex module data?????
This file contains 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
--- | |
zones: | |
- { zone: one.de, policy: rfc5011 } | |
- { zone: thirteen.com, policy: default } |
This file contains 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 | |
# -*- coding: utf-8 -*- | |
import os | |
import ast | |
try: | |
import json | |
except ImportError: | |
import simplejson as json | |
# ============================================================== | |
# main | |
def main(): | |
argument_spec = url_argument_spec() | |
argument_spec.update( | |
zlist = dict(required=True, type='str') | |
) | |
module = AnsibleModule( | |
argument_spec = argument_spec, | |
) | |
zlist = module.params['zlist'] | |
#f = open('/tmp/j', 'w') | |
#f.write(zlist) | |
#f.close() | |
# >> [{'policy': 'rfc5011', 'zone': 'one.de'}, {'policy': 'default', 'zone': 'thirteen.com'}] | |
try: | |
data = json.loads(zlist) # zlist has single quotes ('param': 'value') which is wrong | |
except: | |
data = ast.literal_eval(zlist) | |
res = [] | |
for z in data: | |
res.append(z['zone'].upper()) | |
module.exit_json(changed=True, msg='OK', newdata=res) | |
# import module snippets | |
from ansible.module_utils.basic import * | |
from ansible.module_utils.urls import * | |
main() |
This file contains 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: | |
- localhost | |
connection: local | |
vars_files: | |
- comdata-vars.yml | |
tasks: | |
- name: COMplex DATa | |
action: comdata | |
# zlist="{{ zones }}" | |
args: | |
zlist: "{{ zones }}" | |
# zlist: "{{ lookup('file', 'f.json') }}" | |
register: n | |
- action: debug var=n.newdata |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment