Skip to content

Instantly share code, notes, and snippets.

@joshuaconner
Created February 12, 2014 00:29
Show Gist options
  • Save joshuaconner/8947448 to your computer and use it in GitHub Desktop.
Save joshuaconner/8947448 to your computer and use it in GitHub Desktop.
joshuaconner's Ansible Module Skeleton
#!/usr/bin/env python
#
###############################################################################
# joshuaconner's Ansible Module skeleton
#
# This is a skeleton of an Ansible module I've been using to make quick-and-
# dirty Ansible modules. Just drop the code in `{{ PLAYBOOK_ROOT }}/library`
# and it will be accessible like any other Ansible module.
#
# This is probably not a "best practices" module skeleton, but I'd like it to
# be! So, pull requests, suggestions, comments, etc. are welcome!
#
# License: GNU GPL v3, just like Ansible
###############################################################################
try:
# Put any initial imports here - we can't use module.fail_json b/c we haven't
# imported stuff from ansible.module_utils.basic yet
except ImportError, e:
print "failed=True msg='failed to import python module: %s'" % e
sys.exit(1)
def main():
changed = False
message = ''
module = AnsibleModule(
argument_spec = dict(
# specify possible arguments that can be passed to your module
#
#
# you can specify possible choices
# state = dict(default='present', choices=['present', 'absent']),
#
# required arguments
# name = dict(required=True),
#
# argument type coercion
# count = dict(default=1, type='int'),
)
)
# fill this with info that you want added to the ansible environment
# http://docs.ansible.com/developing_modules.html#module-provided-facts
facts = dict()
# if success ...
module.exit_json(changed=changed, msg=message, ansible_facts=facts)
# ... otherwise, if failure
# module.fail_json(msg="explain why the module failed here")
# import module snippets
from ansible.module_utils.basic import *
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment