We will pass one argument to our custom module and show if we have success or failure for the module executing based on that.
Since all of this is new to us, we will look at the following things:
- The source code of the hello world module
- The output of that module for both success and failure
- The command that we will use to invoke it
Before we get started, all of this is based on the Ansible Developer Guide! The following code is in Python.
We use Python for many scripting tasks, but we are not experts in it. But we believe this code is simple enough to understand:
from ansible.module_utils.basic import AnsibleModule module = AnsibleModule( argument_spec=dict( answer=dict(choices=['yes', 'no'], default='yes'), ) ) answer = module.params['answer'] if answer == 'no': module.fail_json(changed=True, msg='Failure! We failed because we answered no.') module.exit_json(changed=True, msg='Success! We passed because we answered yes...