part of playbook is given below:This is the ansible playbook(main.yml)
- name: setting Info data
set_fact:
application_data:
log_file_name: "{{ log_file_name }}"
log_file_dir: "{{ log_file_dir }}"
- name: call application
custom_application:
verb: 'call'
body: "{{ application_data }}"
register: activate_output
custom_application.py:
this is the custom ansible application getting called from main.yml file.
###couple of imports
def main():
fields = {
"verb": {"required": True, "type": "str"},
"body": {"required": True, "type": "str"},
}
module = AnsibleModule(argument_spec=fields)
verb = module.params['verb']
body = yaml.load(module.params['body'])
application = application()
response = application.call(body)
module.exit_json(changed=True, meta=response)
if __name__ == '__main__':
main()
Application.py: python class that does couple of application related things.
def call(body):
application = {}
application["is_activated"]=True
return application
above the main.yaml and custom ansible module and application class
fatal: [localhost]: FAILED! => {
"changed": false,
"failed": true,
"module_stderr": "",
"module_stdout": "\"changed\": true, \"meta\": {\"is_activated\": true}}\n",
"msg": "MODULE FAILURE",
"rc": 0
}
Module_stdout is as below:
module stdout i truncated the exact module_stdout is given below:
{
"changed": false,
"failed": true,
"module_stderr": "",
"module_stdout": "{
\"invocation\": {
\"module_args\": {
\"body\": \"{
'application_id': '3f17f2a3-0510-457d-a164-72f3a71c6455',
'file_path': '/tmp/vishnu.json',
'log_file_name': '42ae1299-9cbf-49d3-82da-d2d1eb108eef-2017-09-09-11:26:03.log',
'log_file_dir': '/home/oracle/logs/oracle/'
}\",
\"verb\": \"activate\"
}
},
\"changed\": false,
\"meta\": {
\"is_activated\": true}
}\n",
"msg": "MODULE FAILURE",
"rc": 0
}
and i think its a valid json object.
a particular ansible step is failing as shown above with no stderr. and i am also getting warning as above.. let me know where i went wrong
Note: i am sending json data as the output of custom ansible module as well
From
module_stdout
you can see that the opening{
is missing, giving you invalid JSON object, thus module is failing.Check that your application doesn't mess with standard output.