Use content of a file as a variable with Puppet
Every now and then a need to use the content of a file as a variable on an agent node arises. Here’s one way to do it with the help of a custom fact.
First create a custom fact on the puppet server:
Facter.add(:my_file_content) do
setcode do
path = "/path/to/my_file"
File.read(path) if File.exist?(path)
end
end
You can confine this to restrict it to be available only on selected nodes, for example:
How to add OpenID to WordPress with Keycloak
Adding OpenID to Wordpress allows for existing users on a domain to connect without having to manage another account. In this setup, we will be using Keycloak to provide the existing accounts which the OpenID plugin will use.
There are a few plugins for Wordpress that allow this functionality, but we will be using OpenID-Connect-Generic by Daggerhart.
Keycloak Client Setup
First step is to create a client in Keycloak. In the Keycloak web UI, create an openid-connect client by going to Clients and click Create.
Multi-part cloud-init provisioning with Terraform
Cloud-Init is “a standard for customizing” cloud instances, typically on their first boot. It is allows mixing state-based configuration management with imperative provisioning commands (details in our IaC article). By using cloud-init most of the annoyances of SSH-based provisioning can be avoided:
-
Having to use (possibly shared) SSH keys for provisioning
-
Having to have direct network access to the VM being provisioned (may require a VPN connection)
That said, neither cloud-init itself, nor its use within Terraform is particularly well documented. Therefore it can be an effort to create cloud-init-based provisioning that works and adapts easily to different use-cases. This article attempts to fill that gap to some extent.
X11 Connection Rejected
When switching to root after the typical SSH with X11 forwarding enabled this error can appear:
$ X11 connection rejected because of wrong authentication.
$ Error: Can't open display: localhost:10.0
The workaround seems to include copying the MIT-MAGIC-COOKIE-1 from the user who ssh’d in to the root user using xauth. Here’s how:
First verify the $DISPLAY being used and list the MIT-MAGIC-COOKIE-1 used for it :
Data-driven Terraform: Kubernetes cluster in Hetzner Cloud
Terraform does not have a particularly strong decoupling between data and code, at least not from a best practices perspective. It is possible and useful, however, to use data to define Terraform resources - if not for any other reason but to reduce code repetition for common resources that require defining lots of parameters. Here’s an example of setting up a Kubernetes cluster in Hetzner Cloud using Terraform with a “data-driven” approach:
Enabling system tray on Fedora 35 and 36
System tray is a “legacy” tray where various applications (e.g. Nextcloud, Pidgin and Signal) have an icon with which you can interact with the application without actually opening the main application window. I said “legacy”, because phasing it out was the plan in the Gnome 3 project, but it seems like we’re not getting rid of the tray any time soon, if ever.
In any case the system tray is not enabled by default in recent Fedoras, and the proper way to enable it has changed several times in the recent past as Gnome has been upgraded. This outlines the most recent way to do it, and hopefully this one sticks for longer than a year or so.
Terraform Enum data type
In Terraform you have access to basic data types like bool or string. Defining the data type is a good start for starting to improve the quality of your modules. However, you may want to validate that a certain string matches a list of pre-defined options, and if not, fail validation early.
Terraform, unlike Puppet, does not have a built-in Enum data type. However, you can emulate an Enum like this:
Debugging Puppet Bolt inventory plugins
Puppet Bolt handles inventories in a very flexible and powerful manner: you can combine static target definitions and different targets into a single inventory. For example, you can have an inventory which defines some static node names combined with the AWS inventory, or one that combines static nodes with the Vagrant inventory.
Puppet Bolt inventory plugins do their magic and then output what is essentially a static inventory generated dynamically. When dynamic inventory plugins do not work (as in my case) it can be challenging to figure out what is wrong, let alone how to fix it. However, there’s is a very handy way to print out a static version of the entire inventory, including the dynamically created content:
Terraform remote-exec: wait until a webpage is reachable
Terraform’s remote-exec provisioner fails immediately if any command in a script exists with a non-zero exit code. This makes building polling loops a bit more involved than it normally is. So, here is an example loop that checks if a URL can be reached:
while true; do
curl -k https://puppet:8140/puppet-ca/v1 && break || sleep 3
done
When the URL is unreachable, the “||” will ensure that “sleep” gets run, which returns 0. If the URL is reachable, curl itself will return 0 and “&&” ensures that we break out of the loop.
Are Corporate Vision awards fake?
This was a burning question in my head in September 2021 but didn’t have much luck googling it. Here’s our experience and analysis of Small Business Awards by Corporate Vision. Read on to find out whether the awards handed out by Corporate Vision awards truly are a legit or not.
How did we hear about Corporate Vision?
Corporate Vision contacted us in September 2021 announcing us that we were nominated as candidate for being the best company in the ‘IT Infrastructure Management Specialists - Finland’ category for Small Business Awards. At that time (before this blog post) there was very little information online about Small Business Awards or the company behind them. What I learned at that time was that they seemed to be a so-called ‘vanity award’, where winners have been preselected and everything else was just for show. We could not be absolutely sure about that then, and we thought that “winning” might have some marketing value, so we decided to play along and see where it leads us. I will first go through the process, then I’ll try to give an answer the question in the title.