API Create Host - adding host params fails
I can successfully create hosts via the REST API, however, including host_parameters_attributes causes the action to fail with a 500 response and the message, "resource have no errors."
Satellite version: 6.7
My Ansilbe play that successfully creates a new host looks like this:
- hosts: localhost
tasks:
- name: Create Host in Satellite
uri:
url: "https://REDACTED/api/v2/hosts"
method: POST
user: REDACTED
password: REDACTED
headers:
application: json
version: 2
force_basic_auth: yes
validate_certs: no
return_content: yes
status_code: [200, 201]
body_format: json
body: |
{
"host": {
"name": REDACTED,
"build": "true",
"managed": "true","location_id": "4",
"organization_id": "3",
"hostgroup_id": "7",
"subnet_id": 14,
"mac": REDACTED
}
}
This version returns the 500 error:
- hosts: localhost
tasks:
- name: Create Host in Satellite
uri:
url: "https://REDACTED/api/v2/hosts"
method: POST
user: REDACTED
password: REDACTED
headers:
application: json
version: 2
force_basic_auth: yes
validate_certs: no
return_content: yes
status_code: [200, 201]
body_format: json
body: |
{
"host": {
"name": REDACTED,
"build": "true",
"managed": "true","location_id": "4",
"organization_id": "3",
"hostgroup_id": "7",
"subnet_id": 14,
"mac": REDACTED
"host_parameters_attributes": [
{
"name": "ansible_host_config_key",
"parameter_type": "string",
"value": "REDACTED"
}
]
}
}
On the Satellite server in /var/log/foreman/production.log I see this entry:
2021-01-08T12:40:01 [I|app|a23f61ce] Started PUT "/api/v2/hosts/REDACTED" for REDACTED at 2021-01-08 12:40:01 -0600
2021-01-08T12:40:01 [I|app|a23f61ce] Processing by Api::V2::HostsController#update as JSON
2021-01-08T12:40:01 [I|app|a23f61ce] Parameters: {"host"=>{"host_parameters_attributes"=>[{"name"=>"ansible_host_config_key", "parameter_type"=>"string", "value"=>"[FILTERED]"}]}, "apiv"=>"v2", "id"=>"REDACTED}
2021-01-08T12:40:01 [I|app|a23f61ce] Authorized user api-user(API User)
2021-01-08T12:40:02 [I|aud|a23f61ce] Parameter (44) update event on value , REDACTED
2021-01-08T12:40:02 [W|app|a23f61ce] Rolling back due to exception during save
2021-01-08T12:40:02 [W|app|a23f61ce] Action failed
2021-01-08T12:40:02 [I|app|a23f61ce] Rendering api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout
2021-01-08T12:40:02 [I|app|a23f61ce] Rendered api/v2/errors/standard_error.json.rabl within api/v2/layouts/error_layout (0.6ms)
2021-01-08T12:40:02 [I|app|a23f61ce] Completed 500 Internal Server Error in 1375ms (Views: 1.3ms | ActiveRecord: 1049.0ms)