Reputation: 27
I'm calling a custom module delete_sdb_domain.py
in the playbook to delete the Simple DB domain in AWS after delete Simian Army Chaos Monkey. The task can be executed successfully, but there are error message for the Ansible Module.
Here is the playbook:
# call ansible module in the playbook
- name: Delete Simian Army SimpleDB domain
delete_sdb_domain:
sdb_domain_name: "SIMIAN_ARMY_{{ stack_prefix }}"
when:
"stack_query.rc == 0"
tags:
- delete
here is the module delete_sdb_domain.py
:
#!/usr/bin/python
# Delete SimpleDB Domain
from ansible.module_utils.basic import *
import boto3
def delete_sdb_domain(sdb_domain_name):
sdb = boto3.client('sdb')
sdb.delete_domain(DomainName=sdb_domain_name)
def main():
module = AnsibleModule(
argument_spec = dict(
sdb_domain_name = dict(required=True, type='str')
)
)
delete_sdb_domain(module.params['sdb_domain_name'])
if __name__ == '__main__':
main()
and here is the error:
TASK [Delete Simian Army SimpleDB domain]
*************************************************************************
fatal: [127.0.0.1]: FAILED! => {
"changed": false,
"module_stderr": "",
"module_stdout": "",
"rc": 0
}
MSG:
MODULE FAILURE
Upvotes: 0
Views: 4078
Reputation: 68629
Ansible reports an error, because you don't provide the required JSON object with the result.
Have a look at the tutorial on new module development:
# seed the result dict in the object # we primarily care about changed and state # change is if this module effectively modified the target # state will include any data that you want your module to pass back # for consumption, for example, in a subsequent task result = dict( changed=False, original_message='', message='' ) # ... # in the event of a successful module execution, you will want to # simple AnsibleModule.exit_json(), passing the key/value results module.exit_json(**result)
Upvotes: 2