Initialize The Foreman with custom values (seeding)

I’m setting up a new The Foreman instance (using the Docker Compose setup) and I’m trying to reduce the manual setup steps to a minimum. Hence, I’d like use a configuration file or a template to preconfigure e.g.

  • OS (Hosts > Operating Systems)
  • domain (Infrastructure > Domains)
  • host group (Configure > Host Groups)
  • AD integration (Administer > LDAP Auth)
  • Configure reduced UI for unprivileged users

Is there a generic way to make this work?

I apologize if my question seems stupid and the solution is obvious (I’m not a Ruby person). I’ve seen there is “seeding” (e.g. the rake db:seed command) and “seeding templates”. Is that the way to go?

Any hint in the right direction is really appreciated. :+1:

Thanks, Peter

Not sure if this is included the Docker setup, but I would recommend the hammer cli to setup things in an automated way.

A creation of an os would then look like this:

hammer os create --name CentOS --major 7 --minor 8 --description "CentOS 7.8" --architectures x86_64 \ 
    --family "Redhat" --password-hash SHA256 --media "CentOS 7 mirror" --partition-tables "Kickstart default"
1 Like

I am super biased and would have used our Ansible modules for that, having e.g. the OS creation look like this:

    - name: Create CentOS 7
      theforeman.foreman.operatingsystem:
        name: CentOS
        major: "7"
        minor: "8.2003"
        family: Redhat
        password_hash: SHA256
        architectures:
          - x86_64
        media:
          - CentOS 7 mirror
        provisioning_templates:
          - Kickstart default
          - Kickstart default finish
          - Kickstart default iPXE
          - Kickstart default PXEGrub
          - Kickstart default PXEGrub2
          - Kickstart default PXELinux
          - Kickstart default user data
          - Linux registration default
        ptables:
          - Kickstart default

That’d be usually run from an external system against the Foreman.

2 Likes

These are both super-helpful hints and usable approaches, thanks! :hammer_and_wrench: :+1:

The only downside is that you need to install an external tool (either hammer-cli-foreman or Ansible) and run them from the outside (with user/password authentication).

I would have hoped that there was some rake command that would simply take a fixture, maybe a YAML file, which could be run as part of the setup, after the database migration.

Is there nothing like that? How does the “rake db:seed” command work? Is that hard-coded?

for some value of hard-coded. you can see the seeds in the db/seeds.d directory, but to change these you’d have to rebuild the container (or enter a running one, modify the files, and run db:seed again).

there is no “load seeds from this YAML” afaik :frowning:

1 Like

you could add to the compose ansible or hammer containers and execute it via that process as well.

You could create json files and run over them with curl via the api, but…

I sympathize with adding a few custom Ruby files to db/seeds.d, this seems the most straight-forward approach.

I managed to set the simple values of the Operatingsystem object, but the complex types (list values / references) are tricky to fill in, e.g. provision templates, target architectures, installation media of an operating system.

How would I go about that? Any hint is seriously appreciated.