Add host to host collection with uri ansible module

Latest response

I'm working wit uri ansible module with satellite.
I did one playbook to create a new host_collection and it works OK.

  • name: CREATE HC
    uri:
    url: "https://xxxxxx/katello/api/host_collections/"
    user: "{{user}}"
    password: "{{password}}"
    method: POST
    return_content: yes
    force_basic_auth: yes
    validate_certs: no
    body_format: json
    body: '{"name":"{{hc}}","organization_id":"1"}'
    status_code: [200,201,202]

But I want to do a playbook to add/remove host from a host collection.

The api guide indicates use

PUT /katello/api/v2/host_collections/:id/add_systems

  • name: Assign sat server to host_collection
    uri:

    url: "https://xxxxxx/katello/api/host_collections/586/add_hosts/"
    user: "{{user}}"
    password: "{{password}}"
    method: PUT
    return_content: yes
    force_basic_auth: yes
    validate_certs: no
    body_format: json
    body: '{"hosts_ids":"[1280]"}'
    status_code: [200,201,202,204,301,401]

But it doesn´t work.

"json": {
    "displayMessage": "undefined method `map' for nil:NilClass\nDid you mean?  tap", 
    "errors": [
        "undefined method `map' for nil:NilClass\nDid you mean?  tap"
    ]
}, 

The json with the array is badly built?

Responses

I'm with the same problem...

Hello

I got this working with something like this:

results = put_json( username, password, url_kat, + "host_collections/" + str(host_id_collection) + "/add_hosts", json.dumps( { "host_ids": [host_id_number] } )
)

Perhaps it is worth remove the quotes is worth a try?

FROM body: '{"hosts_ids":"[1280]"}' TO body: '{"hosts_ids":[1280]}'