Refactoring of Foreman's template rendering engine - case study

Kamil Szubrycht - Full-Stack Developer
business, case study, foreman, open source, web

Here’s a behind-the-scenes look at how we worked with a large retail company to build a new rendering engine for Foreman templates.

Modern organizations depend on their server infrastructure not only for most IT functions but also for day-to-day business operations. Being able to manage servers effectively is one of the key competencies of any IT department. The larger the company, the bigger the potential cost of suboptimal server management, poor use of automation of repetitive tasks, outdated security, etc.
In today’s article, we describe how we helped one of our clients to improve their Foreman setup and implement a new template rendering engine that plays important role in their IT infrastructure.

The client

Our client is the IT subsidiary of a leading retail company in Europe. We have been supporting their in-house software developers, data engineers, and IT architects in creating digital solutions for their parent company’s customers and employees.

The challenge

This time they reached out to us with a project to develop new features for Foreman’s template rendering:

  1. Provide the possibility to use templates from a Git repository (by default templates were stored in the database)
  2. Add support for using credentials from Hashicorp Vault in the templates.

Considering the client’s requirements, we realized that the existing rendering engine needed refactoring. Therefore we decided to build a new engine which was based on the old one but also included the new features.

What is Foreman and how it generates executable scripts

Foreman is an Open Source application that automates the lifecycle of physical and virtual Linux-based servers (called hosts). It’s used to manage servers across organizations, especially large ones, automate repetitive tasks, and deploy applications. If you’re not familiar with this tool, check out our article about how it helps approach various challenges in IT companies. An important part of Foreman is the template rendering engine. It turns the ERB (Embedded Ruby) templates into executable scripts, for example, a template <%= "#{@host.fqdn} #{@host.ip}" %> produces host.example.com 192.168.1.2. Variables and macros enable access to the data within templates. You can read more about that in the Foreman’s documentation: writing ERB templates, variables, and macros. Over the years, more features have been added to the engine, and the code has become much more complicated.

Our solution

First, we designed a new template rendering system while making sure it covers all the client’s needs. Once it was ready, we also carried out the implementation. The new system is:

  • Fully compatible with the old one, contains all the previously existing features, and passes all tests.
  • Extendable with additional context details (i.e. variables, macros) through Foreman plugins.
  • Divided into modules – we refactored the old monolith engine into modules.
  • Independent of the template source.

From Foreman 1.20, the new template rendering engine replaced the old one.
We also introduced a new way of testing templates by using snapshots, as well as created Foreman plugins adjusted for the new engine:

  • foreman_git_templates plugin adds support for templates from Git repositories. In order for a host to use templates from a Git repository, set the host parameter named template_url.
  • foreman_vault plugin adds support for credentials from Hashicorp Vault by introducing a new vault_secret macro.

Foreman plugins and integrations

Foreman is a powerful tool that can be adjusted to different requirements through third-party or custom plugins. Over the last years, our backend team has worked with Foreman, been active members of the community, and created a number of custom plugins to serve the specific needs of our clients.

If you’re considering Foreman for your project, or already have it implemented, but are missing some functionalities, let’s see how iRonin.IT could help you with that!


Let’s get in touch
Author's Bio
Kamil Szubrycht

Full-Stack Developer

Full-Stack Web Developer with Foreman experience. Coding mostly in Ruby and JavaScript - when nobody is looking. An open source enthusiast. Biker. An occasional chess player. Real Madrid supporter. Addicted to pizza.

Similar articles
Comments

Bulletproof your development with remote team augmentation

Read how
This page is best viewed in portrait mode
Our websites and web services use cookies. We use cookies and collected data to enhance your experience, provide additional communication channels, improve marketing materials and enhance our offer. IRONIN SP. Z O.O. SP. K. is committed to protecting all the data that we collect or process in any way, especially data of personal nature. By accepting these terms you agree to our usage of cookies and processing your data, according to our Privacy Policy, and you declare that your browser settings reflect your preferences. Read more You have the right to revoke this agreement at any time, based on the terms of our Privacy Policy. You can change cookies settings in your browser. If you do not agree with us using cookies and processing your data, please change your cookies settings in your web browser and reject these terms. You can find more information about cookies, your data privacy This site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies. data processing, and your rights in our Privacy Policy.