Using foreman API is fairly simple, in here I’ll show an example using curl.
Using this simple script, you could automate your VM/Bare metal provision process + Puppet configuration in one simple step.
Create a new Host
In this example, I’ve hidden most of the logic in the host group attribute in foreman. meaning that it already knows the Provisioning and Puppet attributes, but its not a problem to define extend the script not to relay on a given hostgroup, or simply override certain default attributes ( such as memory size, or host operation system etc).
Best way to figure out the additional attributes (besides RTFM) is simply to look at foreman log during the creation POST command.
a typical response from foreman, would include the ipaddress (that was automatically assigned), mac address (that was auto generated if its a vm), etc etc.
Note that in order to use the hostgroup, you would need to know its ID, that’s easily done if you simply look at the URL while you edit an existing hostgroup, for example, if your URL is https://foreman/hostgroups/1-base/edit, then the ID is 1.
Delete a Host