Problem:
Not sure where to start with writing Ansible roles for Foreman. I’ve gone through the documentation and imported some of the standard Ansible roles, so I know Ansible integration is available, but I’m not sure where to go from here. Most of what I find is how to use Foreman from Ansible or how to enable the feature, but I’m missing a simple example on how to automate a task like installing and configuring a service on a built host.
Expected outcome:
Find an example playbook somewhere, detailing some of the differences between native Ansible and Ansible playbooks to run in Foreman.
“If you want to add custom roles or collections, place them under /etc/ansible”.
So you should be able to write your own playbooks, put them there, and then import them.
Once you have the roles in place, I don’t think there is any difference between a playbook run by Foreman and any other playbook. When you “run Ansible roles” for your host, an Ansible REX job will be run on the host and the imported playbooks will be executed.
Now, I’ve written some Ansible playbooks for automating network stuff on Cisco and Palo Alto appliances. But how different is writing a playbook for running things via Foreman? Or am I simply overthinking this and are these the same playbooks I would write if running them from my own machine?
It would help if you have specifics. But I believe the only difference would be that Ansible is running on the Foreman server, not the host or wherever you were running Ansible for those appliances. So the available Ansible modules may or may not be the same. Other than that I’m not really aware of any specific differences.
Just to add to Jeremy’s answer: The biggest difference is that you write the role only and not the playbook executing it when using “run Ansible roles”. So you get an inventory created by Foreman via your host selection and the roles will just be included in the playbook in the selected order. So the abstraction removes a bit of control, something some people do not like and other prefer for the simplicity, but this is something you need to keep in mind when designing your role.