Search code examples
ansiblemesosmarathon

Ansible Fatal Error when trying to delete an App on Marathon


I am trying to Post an app on marathon using Ansible and then I am trying to delete the same app with my Playbook. Everything works fine, the only problem is that I am getting below error when I am running my playbook for delete.

fatal: [localhost]: FAILED! => 
{
  "cache_control":"no-cache, no-store, must-revalidate",
  "changed":false,
  "connection":"close",
  "content":"{\"version\":\"2016-10-12T16:51:47.641Z\",\"deploymentId\":\"46edbf12-e837-45c5-9360-9824a4143868\"}",
  "content_length":"92",
  "content_type":"application/json; qs=2",
  "date":"Wed, 12 Oct 2016 16:51:02 GMT",
  "expires":"0",
  "failed":true,
  "json":{
    "deploymentId":"46edbf12-e837-45c5-9360-9824a4143868",
    "version":"2016-10-12T16:51:47.641Z"
  },
  "msg":"Status code was not [201]: OK (92 bytes)",
  "pragma":"no-cache",
  "redirected":false,
  "server":"openresty/1.7.10.2",
  "status":200,
  "url":"http://mywebsite.com:19092/v2/apps/demoansible",
  "x_marathon_leader":"http://10.201.160.1:31392"
}

As you can see above, the json shows successful response and status is 200, also when I check on Marathon UI, the app is deleted. But the only problem is the fatal:[ localhost]: FAILED! => error. Is there any way, I can remove that error?

here is my playbook for delete:

---
- hosts: local
  gather_facts: false
  tasks:
    - 
      uri:
        body: "{{ lookup('file','app.json') }}"
        body_format: json
        force_basic_auth: true
        method: DELETE
        password: password
        status_code: 201
        url: "url/v2/apps/demoansible"
        user: user1

Solution

  • What I see from your playbook is that, you are using it for deleting an app on your marathon, and you have already given your app id in the url, I dont think you need a body in your playbook. Please remove the body and also the status code, and I think it should work fine.

    The reason, you dont need body is that you are using it for deleting. And for deleting a running app on marathon, app id is more than sufficient, you dont need to pass your app.json file to delete an app. This will remove the fatal error which you are facing.

    Hope this helps.