Created
April 8, 2015 03:07
-
-
Save mogi/75d93a4fadb8296b081a to your computer and use it in GitHub Desktop.
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/env python | |
# -*- coding: utf-8 -*- | |
import json | |
import sys | |
import shlex | |
from ansible.module_utils.basic import * | |
DOCUMENTATION = ''' | |
--- | |
module: results_to_list | |
short_description: get list | |
description: | |
- get command output list from command output object | |
options: | |
command_outputs: | |
description: | |
- command outputs | |
default: None | |
required: False | |
type: dict | |
key: | |
description: | |
- filter key | |
default: None | |
required: False | |
type: str | |
rtype: list | |
''' | |
EXAMPLES = ''' | |
- results_to_list: command_outputs="{{arg1}}" key=arg2 | |
''' | |
def _execute(module): | |
results = [] | |
for output in module.params['command_outputs'].get('results'): | |
if not output.get(module.params['key'], None): | |
continue | |
results.append(output.get(module.params['key'])) | |
return results | |
def main(): | |
module = AnsibleModule( | |
argument_spec=dict( | |
command_outputs=dict(default=None, required=False, type='dict'), | |
key=dict(default=None, required=False, type='str'), | |
), | |
supports_check_mode=True, | |
) | |
result = _execute(module) | |
module.exit_json(changed=True, value=result) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment