Set host content view via API/Ansible

Problem: Hello,
I want to set/update content view on a host via ansible, it’s possible to achieve this using API? I didn’t find anything on the foreman API doc API documentation

Really need your help! :sweat_smile:
I know that is possible with hammer cli.

Foreman Ansible Modules’ host module seems to allow you to set the content view: module – Manage Hosts — Ansible Documentation


To set via the API, you’ll need the content view ID and lifecycle environment ID. Then you can update the host via PUT /api/v2/hosts/:id by sending the parameters


For example, if the host ID is 2, CV ID is 2 and LCE ID is 1:

PUT /api/v2/hosts/2

with the request payload like


Side note: I would recommend to always look at the API doc at your local foreman, at, this has the benefit that the docs always match your running Foreman version and includes the API information for all your installed plugins.


:grimacing: hoo how did I miss the ansible doc :sweat_smile: it was there crystal and clear… Thanks @jeremylenz I managed to test with ansible and was successful, and I will try the with API later today.

1 Like