Automate Git pull prior to running Ansible Roles

Hey everyone,

I’m trying to ascertain the best way to update my Ansible roles prior to running them in Foreman. I’m hoping to find an automatic way of syncing my roles from GitHub prior to each task run.

My initial thought was that I could configure the “Ansible Roles - Ansible Default” job template with a pre-task that runs on my foreman-server and makes use of the ansible ‘git’ module, but I’m a little stuck. I was specifically looking for a way to only update just those roles that are about to be used, and I’m also hoping to accomplish this without user input while running the task. I’m wondering if it’s possible to make use of a variable (like maybe @host.all_ansible_roles.present?) to update the roles on my foreman-server before running those roles on all the target hosts.

If anybody has done something like this, I would love to know how you accomplished it!


The suggested approach of finding all assigned roles of host could be achieved through rest api. But, if some role has dependencies, Foreman wouldn’t know about them. Also note, that the pre-task would need to be executed of foreman-proxy host, not target machine itself. Long term, it may be interesting to use Katello repo and mirror it on every proxy, so one would only need to sync it from upstream.

Thanks for the tips, Marek. I’ll do some digging into the Katello option.

Oh sorry if I was misleading you. I think Katello has no option as of today for managing Ansible content. Pulp 3 (not released yet) should already have a plugin for it, but Katello uses Pulp 2 as of now.

1 Like