Playbook showing as failed but actually runs successfully

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
      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”, “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
‘’’

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

4 Likes

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.

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

3 Likes

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