I installed the latest Foreman version 2.5.0 on Debian 10.
I’d like to use Ansible for host provisioning instead of Puppet.
I’m using Ansible 2.9 on the foreman host.
I installed ansible and remote execution plugins as per plugin installation instructions.
I noticed there is an initial host provisioning template for Puppet, but there’s none for Ansible.
Is there an Ansible initial host provisioning template that I could use to provision new hosts and register new hosts?
I’m also having problems registering new hosts on my foreman instance - after running curl command provided by the UI the host show 500 Internal Server Error. I tried to register existing hosts running CentOS 8, Debian 10 and OpenSUSE 15.
I’ll be grateful for any tips and advice you can give me
Can you first confirm that you can properly register a host? ie having access to the repositories according to the distributions used.
The ansible part comes after and takes care of the configuration of the host. Personally, I used Foreman as ansible repository and Ansible tower as well, don’t hesitate if you have any questions.
For the ansible part, you can use ansible_provisioning_callback with Ansible Tower and foreman Foreman :: Plugin Manuals or use Tower API to add host to inventory and run playbooks (or workflow) on it, or even use remote ssh directly.
As @kobena pointed out, there are several options to trigger the Ansible run at the end of provisioning. Ansible does not require any special configuration, the only thing we need is to ensure the SSH public key is installed on the machine. That is done by the remote execution snippet that’s used in the preseed template IIRC. If you succesfully provision a machine, it should trigger one Ansible run of all roles you’ve assigned to the host.
Regarding the registration, can you look at ~foreman/production.log and upload the full traceback from the moment you see the 500 error? That would help with debugging a lot.
Based on your advice I suspected I did something wrong when changing SSL certificates and I had a mismatch which made it impossible to register machines.
Right now I can successfully add a host to foreman using a test playbook with ansible callback for foreman setup as per the instructions found on the foreman webpage.
Took me a fair bit of time to get Ansible to run tasks properly on the hosts but I managed to get it done.
The only question that remains is if there’s an ansible host initial config template or role to provision new machines as unfortunately I cannot use ansible_provisioning_callback (I cannot select it to be run on the host)?
You just need to use the remote execution snippet in your kickstart to deploy ssh keys, and ensure that ansible roles are assigned to your host (easier by using hostgroup). Then “it should trigger one Ansible run of all roles you’ve assigned to the host”.
The ansible provisionning callback needs Tower or AWX to be used.