Tower API Error When Removing Host From Inventory

Not sure if this is a bug or not but I thought I’d see if anyone else has tried this and experienced the same issue. I’m attempting to use the Tower API to add and remove hosts from a temp static inventory. Adding hosts works fine, but when I try to remove that same host, I get the following JSON output error: “"id" field must be an integer.”

`

  • name: Get host ID

uri:
url: https://tower/api/v2/inventories/18/hosts/
method: GET
body_format: json
force_basic_auth: yes
user: “{{ tower_user }}”
password: “{{ tower_pass }}”
validate_certs: no
status_code: 200
register: host_list
when: inventory_action == ‘Remove Host’

  • name: Remove server from, Tower inventory
    uri:
    url: https://tower/api/v2/inventories/18/hosts/
    method: POST
    body:
    id: “{{ host_id[0] | int }}”
    disassociate: true
    body_format: json
    force_basic_auth: yes
    user: “{{ tower_user }}”
    password: “{{ tower_pass }}”
    validate_certs: no
    status_code: 204
    when: inventory_action == ‘Remove Host’

`

Here’s the JSON output when it fails:

`

fatal: [localhost]: FAILED! => {
“allow”: “GET, POST, HEAD, OPTIONS”,
“changed”: false,
“connection”: “close”,
“content”: “{"msg":"\"id\" field must be an integer."}”,
“content_language”: “en”,
“content_length”: “42”,
“content_type”: “application/json”,
“date”: “Tue, 03 Sep 2019 15:21:12 GMT”,
“elapsed”: 0,
“invocation”: {
“module_args”: {
“attributes”: null,
“backup”: null,
“body”: {
“disassociate”: true,
“id”: “806”
},
“body_format”: “json”,
“client_cert”: null,
“client_key”: null,
“content”: null,
“creates”: null,
“delimiter”: null,
“dest”: null,
“directory_mode”: null,
“follow”: false,
“follow_redirects”: “safe”,
“force”: false,
“force_basic_auth”: true,
“group”: null,
“headers”: {
“Content-Type”: “application/json”
},
“http_agent”: “ansible-httpget”,
“method”: “POST”,
“mode”: null,
“owner”: null,
“password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“regexp”: null,
“remote_src”: null,
“removes”: null,
“return_content”: false,
“selevel”: null,
“serole”: null,
“setype”: null,
“seuser”: null,
“src”: null,
“status_code”: [
“204”
],
“timeout”: 30,
“unix_socket”: null,
“unsafe_writes”: null,
“url”: “https://tower/api/v2/inventories/18/hosts/”,
“url_password”: “VALUE_SPECIFIED_IN_NO_LOG_PARAMETER”,
“url_username”: “admin”,
“use_proxy”: true,
“user”: “admin”,
“validate_certs”: false
}
},
“json”: {
“msg”: “"id" field must be an integer.”
},
“msg”: “Status code was 400 and not [204]: HTTP Error 400: Bad Request”,
“redirected”: false,
“server”: “nginx/1.14.1”,
“status”: 400,
“url”: “https://tower/api/v2/inventories/18/hosts/”,
“vary”: “Accept, Accept-Language, Cookie, Origin”,
“x_api_node”: “localhost”,
“x_api_time”: “0.101s”,
“x_api_total_time”: “0.123s”
}

`

I’ve tried converting host_id to int but that doesn’t resolve the issue. host_name and inventory_action are inherited from a Tower survey. Tower version 3.5, Ansible version 2.8.3

try this:

id: “{{ host_id[0] | int * 1 }}”