These days, I wanted to change my puppet environment in foreman. Therefore I thought, I can use the webgui to do that. So started with one hostgroup and just reconfigured the environment and wtf… all configured puppet modules (puppet classes) are gone.
I’m glad that I dumped my database first I changed something but why is foreman deleting all configured modules? I think it deletes all modules, because it is stupid and does not really know which module you have in which environment. That is not really a problem if you have just 2 modules configured, but in my case I had 15 modules for each hosgroup and sub-hostgroup. Restore all that modules out of my mind is not what I wanted to do. But how can you change the environment without all that stupid gui-stuff?
I found a way which worked for me. I did all the changes in the database (postgres).
get backup of foreman db
pg_dump foreman > foreman.dump
connect to foreman database
psql \c foreman;
My configured environments looks like the following:
foreman=# select * from environments; id | name ----+---------- 4 | production 5 | devel 6 | test
I want to change all my devel environments to test environments.
Therefore we need to update the hostgroups and the hosts where our environment is configured.
update hostgroups and hosts
update hostgroups set environment_id = 6 where environment_id = 5; update hosts set environment_id = 6 where environment_id = 5;
If we now take a look at our foreman site, we see, that all relevant hosts are updated to new environment.
That’s it. I don’t know why foreman keeps all modules configured he sees in that specific environment, because he scans all environments if you add a new module.