Testing Ansible roles


Looking for some input on how we can test our custom Ansible roles and Parameters before we import them into Foreman.

To add some context:

  • We have around twenty production Ansible roles in /etc/ansible/roles on our Foreman host (motd, hosts, packages, sudo etc etc)
  • We use the foreman-ansible-modules to maintain global,hostgroup and host parameters in gitlab.
  • Roles are cloned from our production gitlab repo to our Foreman Server
  • We then use remote execution from Foreman to push the roles to our production servers.

Everything works well. But we don’t have a simple workflow to test new Ansible roles and Parameters independently of Foreman.

We can obviously clone our git repo and execute roles from a local branch on a target dev machine, but the parameter_type is only used in Foreman. So, all our vars have to be updated before pushing to prod.

For example, setting the motd using Foreman Ansible Modules looks like this:


   - name: motd_motd
     parameter_type: string
     value: "This is a test message of the day"

But this won’t work outside of Foreman, I have to specifically set the var as below to run it from a local branch on a remote host:

    - motd_motd: "test from local vars"

Is there any way to have Ansible interpret the parameter_type independently of Foreman? We can then test everything before we push to production via gitlab repos.

Any help or alternative approaches would be great. The goal is to have an elegant workflow for testing new Ansible roles and parameters.


Rephrasing my own question:

How does Foreman read in the Host parameters before remote execution applies them?

I’m still looking for a method of testing Ansible roles independently of Foreman but maintaining the parameter formatting used by the Foreman Ansible modules:

  • name: motd_motd
    parameter_type: string
    value: “This is a test message of the day”

Is there a specific Foreman job the renders the parameters ahead of the remote execution?