Last active
November 30, 2017 13:05
-
-
Save juliedavila/2643b67a8e7b91f5d858 to your computer and use it in GitHub Desktop.
New Ansible Module Boilerplate
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 | |
# libraries you import here, must be present on the target node. | |
import os | |
# You can defined other functions up here to make your code more modular. | |
# These functions will need to be called from main(), either directly or through N number of other functions | |
# that eventually lead back to main() | |
def main(): | |
module = AnsibleModule( | |
argument_spec = dict( | |
paramA = dict(required=True, choices=['onechoice', 'secondchoice']), | |
paramB = dict(required=True), | |
paramC = dict(required=True) | |
), | |
supports_check_mode = False, | |
) | |
# Normalize params to make code cleaner | |
paramA = module.params['paramA'] | |
paramB = module.params['paramB'] | |
paramC = module.params['paramC'] | |
# Do logic here, can be calls to other functions above main() | |
# if it is time to exit, successfully | |
module.exit_json(changed=True, somekey='somevalue', otherkey=some_var_value) | |
# if it is time to exit, with an error | |
module.fail_json(msg="Some error message") | |
# import module snippets (must stay here after your code) | |
from ansible.module_utils.basic import * | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment