# Playbook showing as failed but actually runs successfully

**URL:** <https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146>\
**Category:** Get Help\
**Tags:** api, json, playbook\
**Created:** [April 25, 2024, 10:40am UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146 "2024-04-25T10:40:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahawker](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@ahawker](https://forum.ansible.com/u/ahawker)\
**Post date:** [April 25, 2024, 10:40am UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146/1 "2024-04-25T10:40:45Z")

</div>

Hello,

Created a simple playbook to add Dell iDRACs into OME (Open Manage Enterprise). The playbook runs successfully. By that I mean the device is added to OME every time I’ve tested the code. My issue is the playbook’s outcome when ran always comes back as failed. The playbook uses a Dell defined API, first tested in Postman and then added into Ansible so I know the API is fine. I’m doing something wrong in ansible but can’t work out where. Any help appreciated!

code:  
‘’’

- name: Add server into OME  
hosts: localhost  
connection: local  
gather\_facts: ‘no’  
tasks:
  - name: Add device into OME for fresh discovery  
uri:  
url: \>-  
REMOVEDHTTPTOGETPOSTTOPUBLISH://{{ dell\_ome\_server  
}}/api/DiscoveryConfigService/DiscoveryConfigGroups  
user: ‘{{ dell\_ome\_user }}@email.com’  
password: ‘{{ dell\_ome\_password }}’  
method: POST  
body\_format: json  
body:  
DiscoveryConfigGroupName: Discovery-2017033110553636  
DiscoveryConfigGroupDescription: ‘null’  
DiscoveryStatusEmailRecipient: [email@email.com](mailto:email@email.com)  
DiscoveryConfigModels:  
- DiscoveryConfigId: 331105536  
DiscoveryConfigDescription: ‘’  
DiscoveryConfigStatus: ‘’  
DiscoveryConfigTargets:  
- DiscoveryConfigTargetId: 0  
NetworkAddressDetail: 10.20.254.11  
AddressType: 30  
Disabled: false  
Exclude: false  
ConnectionProfileId: 0  
ConnectionProfile: \>-  
{“profileName”:“”,“profileDescription”:“”,“type”:“DISCOVERY”,“credentials”:[{“id”:0,“type”:“WSMAN”,“authType”:“Basic”,“modified”:false,“credentials”:{“username”:“root”,“password”:“FakePassword”,“caCheck”:false,“cnCheck”:false,“port”:443,“retries”:3,“timeout”:60,“isHttp”:false,“keepAlive”:false}}]}  
DeviceType:  
- 1000  
Schedule:  
RunNow: true  
RunLater: false  
Cron: startnow  
StartTime: ‘’  
EndTime: ‘’  
CreateGroup: true  
TrapDestination: false  
use\_proxy: ‘no’  
status\_code: 204  
return\_content: ‘yes’  
validate\_certs: ‘no’  
force\_basic\_auth: ‘yes’  
headers:  
Content-Type: application/json  
Accept: application/json  
register: ome\_template\_device\_delete\_response  
‘’’  
playbook output:  
‘’’  
[WARNING]: No inventory was parsed, only implicit localhost is available  
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match ‘all’

PLAY [Add server into OME] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*

TASK [Add device into OME for fresh discovery] \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
fatal: [localhost]: FAILED! =\> {“access\_control\_allow\_origin”: “\*”, “changed”: false, “connection”: “close”, “content”: “{"DiscoveryConfigGroupId":109,"DiscoveryConfigGroupName":"Discovery-2017033110553636","DiscoveryConfigGroupDescription":"Discovery-2017033110553636","DiscoveryStatusEmailRecipient":"email@email.com","DiscoveryConfigParentGroupId":0,"CreateGroup":true,"DiscoveryConfigModels":[{"DiscoveryConfigId":331105536,"DiscoveryConfigDescription":"","DiscoveryConfigStatus":"","DiscoveryConfigTargets":[{"DiscoveryConfigTargetId":0,"NetworkAddressDetail":"10.20.254.11","SubnetMask":null,"AddressType":3,"Disabled":false,"Exclude":false}],"ConnectionProfileId":0,"ConnectionProfile":"{\"profileName\":\"\",\"profileDescription\":\"\",\"type\":\"DISCOVERY\",\"credentials\":[{\"id\":0,\"type\":\"WSMAN\",\"authType\":\"Basic\",\"modified\":false,\"credentials\":{\"username\":\"root\",\"password\":\"FakePassword\",\"caCheck\":false,\"cnCheck\":false,\"port\":443,\"retries\":3,\"timeout\":60,\"isHttp\":false,\"keepAlive\":false}}]}","DeviceType":[1000],"DiscoveryConfigVendorPlatforms":}],"DiscoveryConfigTaskParam":[{"TaskId":16266,"TaskTypeId":0,"ExecutionSequence":0}],"DiscoveryConfigTasks":,"Schedule":{"RunNow":false,"RunLater":false,"Recurring":null,"Cron":"startnow","StartTime":null,"EndTime":null},"TrapDestination":false,"CommunityString":false,"ChassisIdentifier":null,"UseAllProfiles":null}”, “content\_length”: “1305”, “content\_security\_policy”: “default-src ‘self’ ‘unsafe-eval’; connect-src \*; style-src ‘self’ ‘unsafe-inline’ blob:; script-src ‘self’ ‘unsafe-inline’ ‘unsafe-eval’; img-src ‘self’ blob: data:”, “content\_type”: “application/json;odata.metadata=minimal”, “cookies”: {}, “cookies\_string”: “”, “date”: “Thu, 25 Apr 2024 09:58:40 GMT”, “elapsed”: 19, “json”: {“ChassisIdentifier”: null, “CommunityString”: false, “CreateGroup”: true, “DiscoveryConfigGroupDescription”: “Discovery-2017033110553636”, “DiscoveryConfigGroupId”: 109, “DiscoveryConfigGroupName”: “Discovery-2017033110553636”, “DiscoveryConfigModels”: [{“ConnectionProfile”: “{"profileName":"","profileDescription":"","type":"DISCOVERY","credentials":[{"id":0,"type":"WSMAN","authType":"Basic","modified":false,"credentials":{"username":"root","password":"FakePassword","caCheck":false,"cnCheck":false,"port":443,"retries":3,"timeout":60,"isHttp":false,"keepAlive":false}}]}”, “ConnectionProfileId”: 0, “DeviceType”: [1000], “DiscoveryConfigDescription”: “”, “DiscoveryConfigId”: 331105536, “DiscoveryConfigStatus”: “”, “DiscoveryConfigTargets”: [{“AddressType”: 3, “Disabled”: false, “DiscoveryConfigTargetId”: 0, “Exclude”: false, “NetworkAddressDetail”: “10.20.254.11”, “SubnetMask”: null}], “DiscoveryConfigVendorPlatforms”: }], “DiscoveryConfigParentGroupId”: 0, “DiscoveryConfigTaskParam”: [{“ExecutionSequence”: 0, “TaskId”: 16266, “TaskTypeId”: 0}], “DiscoveryConfigTasks”: , “DiscoveryStatusEmailRecipient”: “[email@email.com](mailto:email@email.com)”, “Schedule”: {“Cron”: “startnow”, “EndTime”: null, “Recurring”: null, “RunLater”: false, “RunNow”: false, “StartTime”: null}, “TrapDestination”: false, “UseAllProfiles”: null}, “location”: “REMOVEDHTTPTOGETPOSTTOPUBLISH://omelab/api/DiscoveryConfigService/DiscoveryConfigGroups(109)”, “msg”: “Status code was 201 and not [204]: OK (1305 bytes)”, “odata\_version”: “4.0”, “redirected”: false, “server”: “Apache”, “set\_cookie”: “rememberMe=deleteMe; Path=/api; Max-Age=0; Expires=Wed, 24-Apr-2024 09:58:59 GMT; SameSite=lax”, “status”: 201, “strict\_transport\_security”: “max-age=31536000; includeSubDomains”, “url”: “HADTOREMOVEHTTPomelab/api/DiscoveryConfigService/DiscoveryConfigGroups”, “x\_content\_type\_options”: “nosniff”, “x\_frame\_options”: “SAMEORIGIN”, “x\_xss\_protection”: “1; mode=block”}

PLAY RECAP \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*  
localhost : ok=0 changed=0 unreachable=0 failed=1 skipped=0 rescued=0 ignored=0  
‘’’

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [April 25, 2024, 12:01pm UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146/2 "2024-04-25T12:01:13Z")

</div>

When posting code, use triple tilde. Reading your output was a bit difficult.

The reason you are getting an error is because your code is expected an HTTP Status code of 204.  
`status_code: 204`

In your output, we see that the server is giving you a status code of 201.  
`“msg”: “Status code was 201 and not [204]: OK (1305 bytes)”`

IIRC, the `status_code` field in the ansible module is optional. You could try not specifying that field, and as long as the HTTP request is successful the module will mark it as changed.

OR, you could change your code to `status_code: 201`.

[Documentation on HTTP Status Codes](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)

---

<div class="post-metadata">

**Author:** ![ahawker](https://avatars.discourse-cdn.com/v4/letter/a/41988e/32.png) [@ahawker](https://forum.ansible.com/u/ahawker)\
**Post date:** [April 25, 2024, 2:09pm UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146/3 "2024-04-25T14:09:39Z")

</div>

Hi Dustin,

Apologies about the ‘’’ code ‘’'. Noted for next time and thanks for letting me know.

That worked, thanks a lot! Ended up forcing a status code of 201 as removing that line still caused an error.

---

<div class="post-metadata">

**Author:** ![Dustin](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/dustin/32/2573_2.png) [@Dustin](https://forum.ansible.com/u/Dustin)\
**Post date:** [April 25, 2024, 2:13pm UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146/4 "2024-04-25T14:13:22Z")

</div>

Just in case you would need to accept multiple status codes, you can provide a list of status codes. So, if for some reason would want to accept both 201 and 204 you could do something like the below:  
`status_code: [201,204]`

[Ansible Documentation for URI Module](https://docs.ansible.com/ansible/latest/collections/ansible/builtin/uri_module.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/ansible/original/1X/1882d9a01da5d8996a862359b0913cc568a39b84.svg) [@system](https://forum.ansible.com/u/system)\
**Post date:** [May 25, 2024, 2:14pm UTC](https://forum.ansible.com/t/playbook-showing-as-failed-but-actually-runs-successfully/5146/5 "2024-05-25T14:14:16Z")

</div>

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
