Gathering facts from Foreman for molecule testing

I have written many roles in our environment but I am finally taking time to learn molecule and try my hand with testing our roles.

We use Foreman to store variables for all our hosts and environments and when we run ansible it will pull the Facts of the host its running against from Foreman. But if I want to run molecule tests on docker / podman … the container will not be registered / configured in Foreman so there would be no facts to gather.

With the command hammer --output yaml host enc-dump --name ${HOST} > ${TMPDir}/${HOST}.yml I can pull the hosts facts out of Foreman and dump them in to a yaml file. But how could I provide that fact file to ansible molecule so it could provision a container like the container was the host actual host the facts are for?

If it sounds overly complicated for testing hear is why. We use a number of account and regions in AWS for our hosts. And depending on the account something simple like mail will be configured differently. In Dev we will send out to the internet. In Prod we will send to AWS SES. If we are sending to SES the SES config will depend on which region the host is in. And thats just mail. Lots of services are setup like this.

When the container runs for the test it could be on my local machine or it could be out of Jenkins or some where else so I need to be able to simulate hosts setup in different regions which I can do by passing in the yaml facts from Foreman for a real host.

You could setup a fact cache when using molecule (jsonfile) and provide the facts via the cache by pre creating a matching file with test data, the downside is you won’t be testing the actual connection for foreman.

I am far more concerned about making sure my roles work as expected then I am about connecting to foreman. But I will say over the last seven or 10 years we’ve had zero issues connecting to foreman.

just pointing out the downsides of the method, it is your context and you’ll always know better what tradeoffs are better for you