Getting latest Rocky Linux AMI ID

Introduction
Rocky Linux 9 is a bug-by-bug clone of Red Hat Enterprise Linux 9 (RHEL 9). We generally recommend using RHEL 9 for mission-critical workloads, but for less important services Rocky Linux 9 is a very good choice if you’re in the Red Hat land already. Official Rocky images are only available in AWS Marketplace, which complicates things when you need to programmatically determine the latest version. This is a common requirement when you do infrastructure as code, for example with Ansible, Terraform or Packer. Although we speak of latest Rocky Linux AMI here, everything in here is applicable for any other AWS Marketplace images, for example Alma Linux.
Fixing ansible-playbook hangs caused by SSH timeouts

Introduction
Ansible is an infrastructure as code tool that uses SSH as its transport mechanism. When the targeted nodes are close, latency-vise to the Ansible controller things usually work fine with the default settings. However, when the targets are far away or latency is big, you may notice that ansible-playbook hangs on some long-running task and never recovers. When you rerun the playbook it may proceed further and then hang at some other task. Or the same task. This is incredibly frustrating, but fortunately also fairly easy to fix.
Alldomains.hosting IPv6 support

We’ve recently started using alldomains.hosting for what we call “programmatic emails”. For that purpose alldomains.hosting is dirt cheap (~1€/year/email address), which makes one quite motivated to suffer through the confusing website to figure out how to buy stuff from them. Once you’ve managed to buy your domain and/or mail services they just “tend to work”. Alldomains.hosting IPv6 support, or lack of it, may be a problem for you, though.
For example, in AWS EC2 you nowadays really want to avoid assigning public IPv4 addresses to EC2 instances as they cost quite a lot. So, you set up an IPv6-only egress-only internet gateway in your VPC and, for the most part, everything “just works”. Then you try to add mail delivery via alldomains.hosting and IPv6 and “boom”, it does not work. According to their support (as of 25.9.2024) their mail servers lack IPv6 support.
Stop EC2 instances automatically with Terraform

Introduction
AWS EC2 is a very convenient place for experimenting with and testing things on virtual machines (or “EC2 instances”). However, it is also very easy to forget such EC2 instances running for no reason, which can become very costly very quickly. Fortunately In AWS computing (e.g. CPU, memory and I/O usage) and storage (disk) usage are billed separately. In other words: if your EC2 instance is stopped, you only pay for its storage. This cuts down the costs significantly, especially if your are using powerful EC2 instance types. So, you definitely should to stop EC2 instances automatically, say, every evening, if you don’t need them to be up. There is no built-in way in to do, though, so this article shows a couple ways it can be done.
Excluding down targets in Prometheus

Excluding down targets in Prometheus is easy. It allow you to monitor volatile systems that start and shut down on demand.
Introduction
Prometheus is an open source metrics and alerting solution used to monitor a wide range of things. Unlike many classic network monitoring systems Prometheus is focused on colleting metrics. This makes it quite easy to do things that would be difficult in others systems. For example excluding down targets in Prometheus is quite trivial. This can be highly useful when you have volatile, static targets that come and go - for example Jenkins slaves (or build agents). Even on such targets you’d want to monitor things like systemd service status, memory usage and disk usage.
Keycloak Javascript policy deployment

Introduction
This article tries to include everything you need to know about Keycloak Javascript policy deployment. By Javascript policies I mean authorization policies of Javascript type attached to Keycloak clients that have authorization enabled. If you don’t know what Keycloak authorization services are, you are probably in the wrong place.
While the process of creating and deploying the JAR files is pretty well documented, it is not altogether clear for the uninitiated how the policies are shown in Keycloak.
Wrong Route53 domain contact details

The symptoms
I recently received and email from Amazon Route53 asking me to verify the contact details for one of our registered DNS domains (replaced here with example.org). And sure enough, I saw wrong Route53 domain contact details in the email:
Subject: Confirm that contact information for example.org is correct.
Message body:
Dear AWS customer,
This message is a reminder to help you keep the contact information for your domain registration up to date. WHOIS records include the following information:
Domains:
example.org
Registrant:
Name: On behalf of example.org owner
Organization Name: Identity Protection Service
Address: PO Box 786
City: Hayes
State/Province: Middlesex
Country: GB
Postal Code: UB3 9TR
Administrative Contact:
Name: On behalf of example.org owner
Organization Name: Identity Protection Service
Address: PO Box 786
City: Hayes
State/Province: Middlesex
Country: GB
Postal Code: UB3 9TR
Phone: +44.1483307527
Fax: +44.1483304031
Email: e793d865-97ab-42ab-805c-50cc36fd9202@identity-protect.org
Technical Contact:
Name: On behalf of example.org owner
Organization Name: Identity Protection Service
Address: PO Box 786
City: Hayes
State/Province: Middlesex
Country: GB
Postal Code: UB3 9TR
Phone: +44.1483307527
Fax: +44.1483304031
Email: e793d865-97ab-42ab-805c-50cc36fd9202@identity-protect.org
The contact information provided above is what is shown in the public WHOIS. If your domain is privacy protected, the information will be different than the contact data you have submitted. To verify your contact information, please open the Amazon Route 53 console to view your current contact information and make any necessary corrections:
https://console.aws.amazon.com/route53/home#DomainDetail:example.org
If your information is accurate, you do not need to take any action.
Important
Under the terms of your registration agreement, providing false contact data can be grounds for the cancellation of your domain name registration.
Regards,
Amazon Route 53
These wrong Route53 domain contact details originate from whois data for the registered domain. One might reasonably expect the whois data to match the contact details for AWS Route53 domain. However, in this case the Route 53 contact details were correct, but whois data seemed to be out of sync with those.
Keycloak realm SMTP settings with Ansible

Introduction
Ansible has reasonably good support for managing various aspects of Keycloak. You can use the community.general.keycloak_realm module to handle realm management, including Keycloak realm SMTP server settings. However, in the true Ansible fashion the documentation looks good, but does not help you much. In fact, documentation only mentions that the smtp_server parameter is a dictionary, but that’s it. To be honest, that’s about as helpful as the description of the RealmRepresentation for Keycloak. This article aims to fill this documentation void. I also want to share some general advise for similar cases that pop up when you manage Keycloak programmatically.
Convert a hash into JSON in Puppet

This article shows you how to convert a hash into JSON in Puppet using a simple ERB template that gets its data from Hiera.
Suppose you have this data in Hiera:
myhash:
mykey:
foo: one
bar: two
Converting a hash into a JSON file on the target node is surprisingly easy. First look up the data:
$myhash = lookup('myhash', Hash)
Then create a simple ERB template (here: mymodule/templates/myhash.erb)
Terraform downloads the deprecated azure provider
You are 100% sure that all your Terraform resources are using terraform-provider-azurerm, yet Terraform attempts to download the deprecated “azure” provider:
$ terraform init
Initializing modules...
Initializing the backend...
Initializing provider plugins...
- Finding hashicorp/local versions matching "2.2.3"...
- Finding latest version of hashicorp/azure...
- Finding hashicorp/azurerm versions matching "3.17.0"...
- Installing hashicorp/local v2.2.3...
- Installed hashicorp/local v2.2.3 (signed by HashiCorp)
- Installing hashicorp/azurerm v3.17.0...
- Installed hashicorp/azurerm v3.17.0 (signed by HashiCorp)
╷
│ Error: Failed to query available provider packages
│
│ Could not retrieve the list of available versions for provider hashicorp/azure: provider registry registry.terraform.io does not have a provider named
│ registry.terraform.io/hashicorp/azure
│
│ Did you intend to use terraform-providers/azure? If so, you must specify that source address in each module which requires that provider. To see which
│ modules are currently depending on hashicorp/azure, run the following command:
│ terraform providers
╵
You grep the state file and find no references to the “azure” provider. You assume that the cause is some nested module that depends on it, but no, that’s not it. You run “terraform providers” and see that indeed, the “azure” provider is required: