Foreman remove file by disabling puppet class

Problem:I define an puppet class for my SSH Keys to write them into /root/.ssh/authorized_keys and i will remove my entrys when i am disabling the puppet class.

My class: exec { ‘add_ssh_keys’:
command => '/usr/bin/cat <<EOF_KEYS >> /root/.ssh/authorized_keys

The import is working but i want to remove them, if i remove the puppet class.
Is this possible with puppet?
What do i need to add?

No. That’s not how puppet works. You define resources. If you define a resource it’s managed. If you don’t define a resource or remove the resource definition from puppet the resource is unmanaged. It won’t be touched not changed.

If you want to manage ssh keys use the module puppetlabs/sshkeys_core from forge puppetlabs/sshkeys_core · Manage SSH authorized keys, and known hosts. · Puppet Forge

There you can add and remove ssh keys from authorized_keys. Then write a class which adds or removes the keys depending on some parameter or code.

Building on this a bit more


$::manage_my_ssh_keys == ‘yesplease’ {

do key stuffz

} else {

do key seuffz ensure absent


Set that param in foreman’s enc (or use smart class param logic

Eventually you have “many params” like this. And all you do is flip them in various ENC places in forenan to get all your configs right

Hello, I added the puppet module and puppet module list presents it. In foreman I ‘click’ to import_environments bot foreman says “No changes to your environments detected”.
I think foreman doesnt like many charakters successively.
Any Ideas?

Please open new topics for new issues.