Recent Blog Posts

Get a list of all available images in the DigitalOcean v2 API

I frequently need to check the slug or id of a particular Droplet image (or in AWS parlance, an AMI) that I can use to launch new DigitalOcean droplets via Ansible. And seeing as tonight I had to search for 'how to get a list of all DigitalOcean images' about the hundredth time, I figured I'd publish this in a blog post so I can find it more easily in the future.

Without further ado:

curl -X GET --silent "https://api.digitalocean.com/v2/images?per_page=999" -H "Authorization: Bearer $DO_API_TOKEN"

This assumes you have exported a valid $DO_API_TOKEN previously. If not, just paste your DigitalOcean API token in place of $DO_API_TOKEN, and then run the command.

It dumps out a ton of JSON, so you can either paste it through something like http://jsonprettyprint.com, or try reading it in all it's unformatted glory. And if the latter, are you a robot?

Bonus trick: If you're on a Mac, you can add | pbcopy to the end of that command to have the output stuck into your clipboard, for easy pasting.

Add a path to the global $PATH with Ansible

When building certain roles or playbooks, I often need to add a new directory to the global system-wide $PATH so automation tools, users, or scripts will be able to find other scripts or binaries they need to run. Just today I did this yet again for my geerlingguy.ruby Ansible role, and I thought I should document how I do it here—mostly so I have an easy searchable reference for it the next time I have to do this and want a copy-paste example!

    - name: Add another bin dir to system-wide $PATH.
      copy:
        dest: /etc/profile.d/custom-path.sh
        content: 'PATH=$PATH:{{ my_custom_path_var }}'

In this case, my_custom_path_var would refer to the path you want added to the system-wide $PATH. Now, on next login, you should see your custom path when you echo $PATH!

Parsing YAML files on the command line using Ruby

I have been working on an infrastructure project that uses YAML files for all inventory and configuration management, and for the most part, if you're using tools like Ansible, CloudFormation, etc., then you don't ever have to worry about the actual parsing of a YAML file, and keys and values in the file are readily accessible since these tools parse them and get them into a readable structure for you.

But there's often little bits of glue code, or infrastructure build/cleanup jobs, where you need to grab one specific value out of a YAML file, and all you have readily available is bash. Luckily for me, I also have Ruby available in the particular environment where I needed to parse the YAML file, so doing this was as easy as:

  1. Defining a little bit of Ruby code which would load the YAML file, then grab a value out of it.
  2. Running that Ruby code using ruby -e (-e for 'evaluate this code), operating on the contents of a YAML file.

And here's how that looked, in my case:

Review: Arc Hub USB-C Adapter

August 2017 update: I just noticed the tech specs on the Arc Hub product page have changed to read: "Arc Hub comes with 1 x Mini Display Port 1.2. Capable resolutions are all HiDPI resolutions, 1080p@60hz, 2560 x 1440 @ 60hz, 3840×2160@30hz." The tech specs used to mention 4K at 60Hz 🤔.

original tl;dr: A capable hub, with some slight design flaws. However, not yet recommended if you want to use it with a 4K monitor, due to compatibility issues with higher refresh rates.

When I bought my 2016 MacBook Pro, I expected a lot of changes. Since I picked the function key model over the more port-laden, but much worse-for-me Touch Bar model, I knew that there would be some growing shrinking pains, going from a generous assortment of five ports on my MacBook Air to two (!) USB-C ports on the MacBook Pro.

How to fix "Host '172.18.0.1' is not allowed to connect" with MySQL Docker

Using the official MySQL Docker image from Docker Hub, I recently ran into the error:

Host '172.18.0.1' is not allowed to connect to this MySQL server

The only change I had made to my docker-compose.yml file was:

mysql:
  image: mysql:5.6
  ports:
    - '3306'
  volumes:
    # Use this option to persist the MySQL DBs in a shared volume.
    - ./mysqldata:/var/lib/mysql:rw,delegated
    # Use this option to persist the MySQL DBs in a data volume.
    # - db_data:/var/lib/mysql

I switched from using a data volume (db_data) to mounting a volume from my host (mysqldata in the current directory), and after the next time I did a docker-compose down and docker-compose up, I started seeing the error about my host not being allowed to connect to the MySQL server.

Pages

Subscribe to Jeff Geerling's Blog