Is it possible to reset deployment templates to a pristine condition?

I have inadvertently purged (almost) all deployment templates and snippets.

My deployment templates included a lot of cruft from previous imports of the community-templates repository, prior to its reorganisation. I would like to restart with a more selective set of suitable templates.

Expected outcome:
I would like to get back to the default set of templates and snippets that are shipped with foreman-core.

Foreman and Proxy versions:
1.21 on Debian amd64 via packages

Many thanks.

I have postgresql database dumps easily accessible. I’m just wondering if there is an easier way.


if I understand your request correctly, just run foreman-rake db:seed. All templates we ship (and are locked for editting) will be overridden to default content. This happens automatically with every upgrade. People who modify templates are suggested to clone them first instead of unlocking. There used to be a logic that if we saw some audit records, we wouldn’t reseed the template, but IIRC that’s gone and default templates are always updated.

Hmm. OK, thanks.
That has appeared to restore some provisioning templates, but not those that I would have expected to see, and no snippets.

$ sudo foreman-rake db:seed
Seeding /usr/share/foreman/db/seeds.d/020-permissions_list.rb
Seeding /usr/share/foreman/db/seeds.d/020-roles_list.rb
Seeding /usr/share/foreman/db/seeds.d/030-auth_sources.rb
Seeding /usr/share/foreman/db/seeds.d/030-permissions.rb
Seeding /usr/share/foreman/db/seeds.d/035-admin.rb
Seeding /usr/share/foreman/db/seeds.d/040-roles.rb
Seeding /usr/share/foreman/db/seeds.d/050-taxonomies.rb
Seeding /usr/share/foreman/db/seeds.d/060-architectures.rb
Seeding /usr/share/foreman/db/seeds.d/070-provisioning_templates.rb
Seeding /usr/share/foreman/db/seeds.d/080-partition_tables.rb
Seeding /usr/share/foreman/db/seeds.d/090-report_templates.rb
Seeding /usr/share/foreman/db/seeds.d/100-installation_media.rb
Seeding /usr/share/foreman/db/seeds.d/110-smart_proxy_features.rb
Seeding /usr/share/foreman/db/seeds.d/130-compute_profiles.rb
Seeding /usr/share/foreman/db/seeds.d/150-bookmarks.rb
Seeding /usr/share/foreman/db/seeds.d/160-mail_notifications.rb
Seeding /usr/share/foreman/db/seeds.d/170-notification_blueprints.rb
All seed files executed

Resulting table.

It seems to have populated the table with all of those templates we have ever used, but none of the snippets that are still required by some of those templates.

That may be a bug, snippets should be updated too of course. I’m not at a computer now to verify, but probably worth raising a redmine issue.

That sounds a little bit, like your list is filtered by the association to an organization. Can you recheck with organization==any and location==any?

Thanks both for the replies. I really thought that the filter by organization/location was going to reveal them all, but it turns out that I was already on a view with the organization==any and location==any filter applied.

I have also checked the same thing with hammer template list and it shows the same list.

~$ hammer template list
ID  | NAME                               | TYPE     
108 | Community Preseed default          | provision
106 | Community Preseed default PXELinux | PXELinux 
105 | Community Preseed default finish   | finish   
33  | FreeBSD (mfsBSD) PXELinux          | PXELinux 
31  | FreeBSD (mfsBSD) finish            | finish   
32  | FreeBSD (mfsBSD) provision         | provision
117 | Openc Preseed default              | provision
118 | Openc Preseed default PXELinux     | PXELinux 
119 | Openc Preseed default finish       | finish   
16  | Preseed default                    | provision
18  | Preseed default PXELinux           | PXELinux 
17  | Preseed default finish             | finish   

I’ll head over to redmine to raise an issue.

This logic is actually there which is likely the reason they were not reimported.
You could try deleting the audits removing the templates from the db then rerun the foreman-rake db:seed task

OK, that’s great. Thanks @tbrisker I will try it. Is there an easy way to remove the audits, or should I just use a psql cli and truncate the audits table?

you can use foreman-rake console and run something along the lines of

Audit.where(auditable_type: 'ProvisioningTemplate', action: 'destroy').destroy_all

but keep in mind that would remove any audits for deleted templates from the record.

Thanks @tbrisker, that worked a treat. I now have all of the defaults back again. Marking as solved. Cheers all.

Should we continue skipping some templates that have audits records? I suppose it would make more sense to always enforce the up to date version for also snippets. The reason probably was that users can’t use their own snippets easily, their names are hardcoded in main templates. But it looks quite confusing now. Or we should provide a button “reset all snippets/templates” to default.

Perhaps we could use the capability in the foreman_templates plugin to sync from the local directory in the foreman install?

Do I hear let’s merge this plugin to core? :slight_smile: Note that it has ~10 new settings :slight_smile: