Using Foreman 3.7 and Puppet 7.
Background:
I want to be able to make quick ad-hoc environments for testing of puppet code. However, I also want there to be a single source of truth for environment assignments; I don’t want hosts out in the infrastructure randomly switching to different environments.
Foreman is set up as an ENC (default, out of the box installation) and I am using r10k to deploy my manifests from all git branches into environments. Generally there is only production, plus whatever branch I am developing on, named according to the work I’m doing.
I can create the new environments (and delete the old) with r10k deploy environment -v -m
(-m optional in most cases unless adding new modules to puppetfile). Deletion works this way also since I configured /etc/puppetlabs/r10k/r10k.yaml
to contain:
deploy:
purge_levels: [ 'deployment', 'environment', 'puppetfile' ]
I can check host environment assignments from the command line:
hammer host info --fields 'Puppet environment' --name server.example.com
And, I can sometimes set the environment on the command line as well:
hammer host update --name server.example.com --puppet-environment some_env
However, after creating a new branch in git, running r10k to create the corresponding environment, and then attempting to run the above update command, I get:
Could not update the host:
Error: environment not found.
I can get around this by going into the Foreman UI, going to “environments” and clicking “import environments from puppetserver.example.com” (N.B.: the puppet server and foreman are the same server). However, I would like to avoid this step, and know how to do it in the command line instead.
So the question is: How can I refresh foreman’s knowledge of puppet environments from the command line?
(It’s worth mentioning, the out of date knowledge goes both ways: if I remove an environment, Foreman will still let me assign hosts to that environment until refreshed through the UI. I thought there should be something that automatically updates this, but running puppet on the foreman server didn’t do it.)