Last active
October 27, 2015 10:18
-
-
Save draganHR/e5dbba2319ab03c5a0e0 to your computer and use it in GitHub Desktop.
Custom ansible module
This file contains hidden or 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 -*- | |
DOCUMENTATION = ''' | |
version_added: "1.0" | |
module: custom | |
short_description: Custom ansible module | |
description: | |
- Custom ansible module | |
- Put into ./library/ dir | |
''' | |
EXAMPLES = '''Usage examples''' | |
import os | |
def main(): | |
module = AnsibleModule( | |
argument_spec=dict( | |
success=dict(default=True, type='bool'), | |
foo=dict(required=False, type='str'), | |
bar=dict(required=False, type='str') | |
) | |
) | |
success = module.params['success'] | |
result = {'changed': False, | |
'foo_was': module.params.get('foo', None), | |
'bar_was': module.params.get('bar', None)} | |
if success: | |
module.exit_json(**result) | |
else: | |
module.fail_json(**result) | |
# include magic from lib/ansible/module_common.py | |
#<<INCLUDE_ANSIBLE_MODULE_COMMON>> | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment