Remove production environment

I have created a new Puppet environment and tried to delete the default ‘production’ out of Foreman. However, it constantly gets recreated for some strange reason. The puppetserver logs shows that it is creating it on its own but I cannot determine where this is defined.

2019-04-25 12:07:10,650 INFO  [qtp1382248809-85] [puppetserver] /File[/etc/puppetlabs/code/environments/production]/ensure created

Can you tell a bit more about your environment? Do you use the theforeman-puppet module to manage your Puppetserver? That by default tries to ensure a few environments, depending on the exact version.

@ekohl I did not specify any foreman-installer options besides for the various certificates, so I imagine it may be defaulting to a module of some sort, just judging from the log entry above. It’s running 1.21.0, on a CentOS 7.6 VM.

Hi,

when importing environments, the environments that are imported are determind from your Puppet server’s availabe environments (by default found at /etc/puppetlabs/code/environments). If you do not use the default production environment, try to get rid of it there.
As @ekohl mentioned, if you use puppet modules to manage your puppet master, the module might recreate it. Foreman-installer uses theforeman-puppet, which is how the environment probably got created in the first place.
After removing it from the master’s environment path and making sure it does not get automatically recreated, the issue should be solved.

After removing it from the master’s environment path and making sure it does not get automatically recreated, the issue should be solved.

How do I determine that theforman-puppet is being applied to my foreman/puppetmaster server? The foreman server belongs to the production environment currently and does not have any class applying with that name. I assume it is being defined elsewhere as a part of being installed by the foreman-installer?

The class is applied once during every run of “foreman-installer”. Unless you rerun the installer, it should not be applied again unless you defined that yourself.
To explain this a little more: foreman-installer is basically a big wrapper around a “puppet apply” command with a lot of modules applied simultaniously. The installer does not setup any puppet classes for recurring application through the regular puppet agent/server mechanisms though.

My apologies for starting this thread back up again, but I still have not really gotten to the bottom of this. I understand that if you re-run foreman-installer it will re-create ‘production’ environment and create the module directory, however there are other times where it just mysteriously gets recreated with no apparent reason, even after I explicitly went and deleted it. I’m guessing something is run by puppetserver that resets it?

The puppet-agent package re-creates it on update. I’ve opened https://tickets.puppetlabs.com/browse/PA-2781 about this, but it was closed as WONTFIX.

Hm damn. I suppose it’s not a functional issue but quite annoying when I’m trying to keep the environments neat and organized.

Is there a way to hide an environment? It seems like I can add it to /usr/share/foreman/config/ignored_environments.yml but it still re-appears in Foreman.

Environments are automatically created when a host reports it. Do you have any agents reporting themselves in the production environment?

I may have some agents with config still saying production but they been assigned to prod in Foreman. When the agent runs, it will show a warning. I’m guessing even thought it is resolving the catalog to the right environment, the fact that it indicated production to puppetserver, that is causing it to be created.

That would be it. If Foreman is set up as the ENC it will enforce the environment to what’s set in Foreman.