Contributing to Go Projects

Contributing to projects on GitHub is a great way to learn, contribute, and help make the software you use better. Normally, you would just make a fork of the project and then clone your fork and do your work. Then you would push to a branch in your fork and open a pull request for that branch. Go is a little different however. Since the imports are specific paths to GitHub/GitLab/etc projects you can’t necessarily just fork the project and do work in your fork....

April 20, 2020 · 2 min · 299 words · John Hooks

Testing Terraform with Terratest

This should be another short one. One of the advantages of IaC (infrastructure as code) is the fact you can test the things you write. There are multiple tools to test your Terraform configs with, but Gruntwork has created an awesome Go package to test your Terraform configs called Terratest. The advantage to Terratest is you just write Go like you would with anything else and it just works. Here’s an example module to create an ec2 instance:...

March 6, 2020 · 2 min · 355 words · John Hooks

Using Terraform and Ansible Together

This should be a short one. So Ansible has dynamic inventories however I’ve found it a bit slow with VMware if you have a lot of infrastructure to parse through (a lot being around 3,000 VMs in your vCenter and slow being around 15 minutes). I also couldn’t figure out a way to use tags to limit what you’re searching on. This admittedly could have changed recently but since I’ve been using this method I haven’t tried too hard to find out....

February 1, 2020 · 2 min · 219 words · John Hooks

Using AlertManager Webhooks

The defacto Alerting tool used with Prometheus is Alertmanager. Prometheus sends a notification to Alertmanager whenever a rule is triggered. Alertmanager then takes that notification and sends it to whatever receiver(s) you have defined in your config. It supports quite a few options: email, hipchat, pagerduty, pushover, slack, opsgenie, victorops, webhook, and wechat. For this post I’m focusing on the webhook receiver. First let’s set up our Alert struct: type Alert struct { Receiver string `json:"receiver"` Status string `json:"status"` Alerts []struct { Status string `json:"status"` Labels struct { Alertname string `json:"alertname"` Service string `json:"service"` Severity string `json:"severity"` } `json:"labels"` Annotations struct { Summary string `json:"summary"` } `json:"annotations"` StartsAt string `json:"startsAt"` EndsAt time....

October 19, 2019 · 3 min · 555 words · John Hooks

Using Make for SysAdmin Tasks

When most people hear about make they think of compiling source code. While that is often what it’s used for, there are other good uses as well. Here’s an example of using it with Terraform/Ansible to build your infrastructure. Make has some advantages over just using a shell script. One is the native concept of dependencies. You can easily define which targets are dependencies of other targets. Make also has some idempotence baked in (as long as everything isn’t a phony target)....

August 11, 2019 · 3 min · 609 words · John Hooks

Ansible Modules with Go

Since Ansible 2.2 you can use binary applications as modules for Ansible. This means you can write modules in languages other than Python. The downside is that the modules aren’t integrated as well as if they were written in Python with Ansiballz. The binary modules only takes the filename as an argument which is a temporary file containing the JSON data of the modules parameters. I took the boilerplate code that Ansible had here and created a small module to generate a random password....

June 30, 2019 · 3 min · 499 words · John Hooks

Ansible and Jenkins Remote Triggers

Ansible Tower has an awesome feature that I’ve talked about before called provisioning callbacks. It’s hard to beat their simplicity, one click of a button and you have an API endpoint and a key to use. However you can replicate this in Jenkins with just about the same amount of work. Coming from using both Tower and Jenkins, I currently prefer to use Jenkins. I find it a little more flexible....

June 18, 2019 · 2 min · 312 words · John Hooks