cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
421
Views
0
Helpful
0
Replies

API Error with Ansible API on Cisco Catalyst Center

jan-hasper
Level 1
Level 1

Hello everyone,
maybe someone could help me. Or even has the same problem as me. Is there a way to have the following command repeated in Ansible if an module error occurs there?

The command i want to repeat:


          - name: Lade Task Info für {{__result.dnac_response.response.taskId}}
            cisco.dnac.task_info:
              dnac_host: "{{dnac_host}}"
              dnac_username: "{{dnac_username}}"
              dnac_password: "{{dnac_password}}"
              taskId: "{{ __result.dnac_response.response.taskId }}"
            register: __result_task
            until: "'dnac_response' in __result_task"
            retries: 3
 
The error that randomly occurs:
 
TASK [Lade Task Info für 4356b198-20ee-4150-9391-51c175eb279c] *****************13:14:31An exception occurred during task execution. To see the full traceback, use -vvv. The error was: dnacentersdk.exceptions.ApiError: [400] Bad Request - The request was invalid or cannot be otherwise served.
fatal: [localhost]: FAILED! => {"msg": "Unexpected failure during module execution: [400] Bad Request - The request was invalid or cannot be otherwise served.", "stdout": ""}

 

If I repeat the task manually wiht the same values it works without problems.
So i wanted to repeat the task on a failure. 

For this case Ansible has normaly an builtin Repeat function for tasks (until) but this functionallity seems not to work in this case, because the task module fail instead of the api request.

If I add the attribute "ignore_errors: true" to the above task. The playbook runs without a problem. If the error occurs, Ansible skips the task and continue with the next action. (Works as designed)

But instead of Skip the Task, i want Ansible to Repeat the Task on a failure.

Are there a way to do this?

Thank you very much for your help. 

 
0 Replies 0