Vendor attribute of templates?

Problem: I have an environment were templates are created by the customer and imported via the templates plugin. Now template names tend to be long even without a prefix with the company name. We stumbled over the attribute vendor via the search. It is set to Foreman for those imported by Foreman during installation/upgrade. With a bit of research I found this is done via the seeding of the database with the seed_helper. So it is only a parameter of this function and not exposed as an attribute of the templates so it could be set. This is very likely the reason why no other templates have the vendor set.

Expected outcome: I would like to set the vendor somehow in the workflow, could be from metadata or via a setting of the template plugin. This seams impossible now, and I even have no idea where to start with the implementation to open at least an issue.

Foreman and Proxy versions: 3.13

Foreman and Proxy plugin versions: 3.13

Distribution and version: CentOS Stream 9

I haven’t tested any of this, but maybe this will get you started?

In structure.sql we can see the schema of the Templates table. (Run bundle exec rails db:schema:dump if you don’t have this file.)

CREATE TABLE public.templates (
    id integer NOT NULL,
    name character varying(255),
    template text,
    snippet boolean DEFAULT false NOT NULL,
    template_kind_id integer,
    created_at timestamp without time zone,
    updated_at timestamp without time zone,
    locked boolean DEFAULT false,
    "default" boolean DEFAULT false,
    vendor character varying(255),
    type character varying,
    os_family character varying(255),
    job_category character varying(255) DEFAULT 'Miscellaneous'::character varying,
    provider_type character varying(255),
    description_format character varying(255),
    execution_timeout_interval integer,
    description text,
    ansible_callback_enabled boolean DEFAULT false,
    cloned_from_id bigint
);

So I see from this that vendor is a normal string database field, and we should be able to set it in the normal way via template.vendor = xxx.

I see here in the base Template model an import_custom_data method:

It says it can be overridden in Template children classes. You didn’t mention which kind of templates these are? I’m assuming provisioning. I see this method is already overridden in provisioning_template.rb: foreman/app/models/provisioning_template.rb at 0ea26858fdc8d2c6ce933f693e4003d7e4e4cbdd · theforeman/foreman · GitHub

So I think you could maybe add to the existing method in provisioning_template.rb

template.vendor = @importing_metadata['vendor']

and see if that does it.

1 Like

Hey there, as Dirk has kindly taken this question to the forum, I immediately tried what Jeremy suggests. Unfortunately, without success. Maybe someone has a better idea?

In the past I’ve modified the debian.rb to fit our custom deployment, and it worked, but I am not a developer. This time I simply edited the provisioning_template.rb and tried adding the line template.vendor = @importing_metadata['vendor'] at the beginning or end of the import_custom_data function. Then I added vendor = Dataport to a template and restarted foreman.service and foreman-proxy.service. Still, there is only vendor = Foreman in the search. Am I missing something obvious?