Skip to content

Instantly share code, notes, and snippets.

@draganHR
Last active October 27, 2015 10:18
Show Gist options
  • Save draganHR/e5dbba2319ab03c5a0e0 to your computer and use it in GitHub Desktop.
Save draganHR/e5dbba2319ab03c5a0e0 to your computer and use it in GitHub Desktop.
Custom ansible module
#!/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