Error add host to host collection with uri module api rest operations with satellite

66 views
Skip to first unread message

Alberto Jimenez Lozano

unread,
Oct 23, 2018, 4:34:44 AM10/23/18
to Ansible Project
I'm working wit uri module  with satellite.
I do one playbook for create a new host_collection and it works OK.


- name: CREATE HC 
    uri:
       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, and the urls that appears in the api guides fails.

For api v1  the api guide indicates use PUT /katello/api/v2/host_collections/:id/add_systems




I did this playbooks and it fails:


- name: Assign sat server {{server}} to {{host_collection}}
    uri:
       user: "{{user}}"
       password: "{{password}}"
       method: PUT
       return_content: yes
       force_basic_auth: yes
       validate_certs: no
       body_format: json
       body: '{"system_ids":"[972,1280]"}'
       status_code: [200,201,202,204,301,401]

The message error is 404 error

The page you were looking for doesn't exist (404)
The page you were looking for doesn't exist





Adrian Sebastian Dutu

unread,
Oct 23, 2018, 5:29:35 AM10/23/18
to Ansible Project
Can you do a get on both of those ids (972,1280)?  Seems like one of them is not existing.

Alberto Jimenez Lozano

unread,
Oct 23, 2018, 5:39:41 AM10/23/18
to Ansible Project
The both hosts exists.

I did the same operation api rest using hammer with -d option and I saw the command that uses.

[ INFO 2018-10-23 11:24:05 API] PUT /katello/api/host_collections/586/remove_hosts
[DEBUG 2018-10-23 11:24:05 API] Params: {
    "host_ids" => [
        [0] "1280"
    ]
}
[DEBUG 2018-10-23 11:24:05 API] Headers: {}
[DEBUG 2018-10-23 11:24:05 API] Using authenticator: HammerCLIForeman::Api::InteractiveBasicAuth
[DEBUG 2018-10-23 11:24:05 API] Response: {
    "displayMessages" => {
        "success" => [
            [0] "Successfully removed 1 Host(s)."
        ],
          "error" => []
    }

Then I removed de host with id 1280 from host_collection and I tried to add the host to hostname, but it fails.

  - name: Assign sat server {{server}} to {{host_collection}}
    uri:
    
       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]


    "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?

Brad Van Orden

unread,
Oct 23, 2018, 7:44:48 AM10/23/18
to Ansible Project
Two things:

  1. Try removing the trailing slash in the url.
  2. Try: url: https://xxxx/katello/api/v2/host_collections/{{ hc_id }}/add_systems
Haven't attempted the api with satellite yet.  So, don't have any direct experience.

Alberto Jimenez Lozano

unread,
Oct 23, 2018, 8:58:31 AM10/23/18
to Ansible Project
It fails too.

  - name: Assign sat server {{server}} to {{host_collection}}
    uri:
       user: "{{user}}"
       password: "{{password}}"
       method: PUT
       return_content: yes
       force_basic_auth: yes
       validate_certs: no
       body_format: json
       body: '{"host_ids":"[972]"}'
       status_code: [200,201,202,204,301,401]

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

Alberto Jimenez Lozano

unread,
Oct 23, 2018, 11:20:44 AM10/23/18
to Ansible Project
I changed the playbook and it runs ok.

  - name: Assign sat server {{server}} with id {{host.json.id}} to {{host_collection}} with id {{hc_id}}
    uri:
       user: "{{user}}"
       password: "{{password}}"
       method: PUT
       return_content: yes
       force_basic_auth: yes
       validate_certs: no
       body_format: json
       body: '{"host_ids":["{{host.json.id}}"]}'
       status_code: [200,201,202,204,301,401]

Brad Van Orden

unread,
Oct 23, 2018, 12:42:49 PM10/23/18
to Ansible Project
Great!  :)
Reply all
Reply to author
Forward
0 new messages