Unable to create and update exiting host entry to be managed through the API.
Foreman 1.21.3
I am able to create a simple host with this API call.
curl -s -H "Accept:application/json,version=2" -H "Content-Type:application/json" \
-X POST -u ${FOREMANUSER}:${FOREMANPASSWORD} -k \
-d '{"host":{"environment_id":"'${ENVIRONMENT_ID}'","hostgroup_id":"'${HOSTGROUP_ID}'","host_parameters_attributes":[{"name":"app_tier","value":"'${APPTIER}'"}],"location_id":"'${LOCATION_ID}'","managed":"false","name":"'${SERVERNAME}'","organization_id":"13"}}' \
${FOREMANURL}/api/hosts
However if I add the managed option or try to add it later I tried this code and receive the below message.
curl -s -H "Accept:application/json,verion=2" -H "Content-Type:application/json" \
-X PUT -u ${FOREMANUSER}:${FOREMANPASSWORD} -k \
-d '{"host":{"operatingsystem_id":"Linux","architecture_id":"1","managed":"true","interfaces_attributes":[{"identifier":"eth0","mac":"00:0d:3a:cf:ad:83","managed":"false"}]}}' \
${FOREMANURL}/api/hosts/${SERVERNAME}
ERROR:
{
"error": {"message":"PG::ForeignKeyViolation: ERROR: insert or update on table \"hosts\" violates foreign key constraint \"hosts_operatingsystem_id_fk\"\nDETAIL: Key (operatingsystem_id)=(0) is not present in table \"operatingsystems\".\n: UPDATE \"hosts\" SET \"managed\" = $1, \"architecture_id\" = $2, \"operatingsystem_id\" = $3, \"updated_at\" = $4 WHERE \"hosts\".\"id\" = $5"}
}
Any help is much appreciated.
Cassuis