0
votes

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

1
anyone if knows the solution let me knowVishnu Imp
show you playbook tasks, really hard to guess like thisArbab Nazar
added basic template of the code let me know where the prob exists @ArbabNazarVishnu Imp
anyone? knows please give a shotVishnu Imp
If you save the module stdout to a text file and feed it through one of the on-line JSON parser/linter tools (use Google and search for "json validator"), does the JSON pass the tests?dan_linder

1 Answers

0
votes

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.