I miss travel, and I miss flying. At the end of March Lufthansa canceled two transatlantic flights I had booked, and that was that; no more flying for me (or for almost anybody else). Is that a reason I’m currently interested in IATA airport codes? Maybe it’s the desire to fly to far-away places.

I began using a list of six thousand airport codes when I developed the first Ansible training, using them as fodder in an application students have to set up, and I decided to use the same data set in an exercise for an advanced Ansible training we’re developing.

The problem with the data I had is that I was about 97.2% sure that I was permitted to use it, but there wasn’t a really clear license associated with it. I’ve meanwhile found OurAirports; they provide a public domain data set, and on the weekend I had a bit of fun with it.

First I wrote an HTTP airport data server which will be running on lab machines. Students will be tasked with the assembly of an Ansible lookup plugin to obtain data from that server for use in templates. (I should probably clarify that my trainings are designed to run without a connection to the Internet – there have been a number of occasions when I’ve had to give trainings in environments which just do not permit their users to use such resources, hence the local service.)

   vars:
      fra: "{{ lookup('airport', 'fra') }}"
   tasks:
      - debug: var=fra
TASK [debug] ************************************************************************
ok: [localhost] => {
    "fra": {
        "cc": "DE",
        "city": "Frankfurt am Main",
        "iata": "FRA",
        "id": "2212",
        "lat": "50.033333",
        "lon": "8.570556",
        "name": "Frankfurt am Main Airport",
        "osm": "https://openstreetmap.org/?mlat=50.033333&mlon=8.570556&zoom=12",
        "type": "large_airport"
    }
}

Just put it in the DNS!

I thought it’d be amusing to provide the public domain data via the DNS, so I did just that. Each airport has a couple of TXT and a LOC record associated with it. The domain name is the 3-letter IATA code:

$ dig +short BCN.air.jpmens.net TXT
"cc:ES; m:Barcelona; t:large, n:Barcelona International Airport"
$ dig +short BCN.air.jpmens.net LOC
41 17 49.560 N 2 4 42.456 E 4.00m 1m 10000m 10m

we also provide a URI which loads an OpenStreetmap.org map to the correct location, and if it’s in the source data, a URI to the Wikipedia page:

$ dig +short CDG.air.jpmens.net URI
10 1 "https://openstreetmap.org/?mlat=49.012798&mlon=2.55&zoom=12"
10 2 "https://en.wikipedia.org/wiki/Charles_de_Gaulle_Airport"

You can obtain the IATA codes indexed by city, providing you spell it as OurAirports has, and in addition to IDNA names I’ve un-unicoded the names, so Münster becomes “munster”, and Tromsø becomes “tromso”. Query the domain for TXT records for the city:

$ dig +short PARIS.air.jpmens.net TXT
"PHT," "PRX," "LBG," "CDG," "ORY"

I generate a file with resource records I then $INCLUDE into a zone master file, and I’m making this zone data file available in this repository for self-hosting. Do tell me if you use it, and I’ll add a pointer to your DNS server if you like.

I assume the data is relatively static (who is building airports nowadays – even BER has been completed but marked “closed”), but if we should notice it’s very volatile we can easily add dynamic DNS updates to update the DNS on the fly.

Whether this is useful is in the eye of the beholder. I can say, that I quite frequently use my country-code lookup service in the DNS.

$ dig +short JP.cc.jpmens.net TXT
"JAPAN"

So, have I now finally earned myself this mug?

put it in the DNS mug

As usual, do talk to me if you have ideas for improvement.

Updates

  • Standing of the shoulders of a giant, I’ve added support for IDNA in the city to IATA mappings; use a client which has IDNA support to query for “düsseldorf”
  • Mentioned on Stéphane Bortzmeyer’s on peut tout mettre dans le DNS, même les codes postaux.
  • Oli Schacher whipped up a service which provides the locations of postal codes in Switzerland via the DNS in the zone zipdns.ch, e.g. via the looking glass: zipdns via the looking glass
  • Inspired by Stéphane’s and Oli’s work on zip codes, I’ve set up an additional zone with forward/reverse lookups of zip codes in Germany (Postleitzahlen), based on publicly available data.
  $ dig PASSAU.zipde.jpmens.net TXT
  ;; ANSWER SECTION:
  PASSAU.zipde.jpmens.net. 604800	IN	TXT	"94036"
  PASSAU.zipde.jpmens.net. 604800	IN	TXT	"94034"
  PASSAU.zipde.jpmens.net. 604800	IN	TXT	"94032"

  $ dig 94034.zipde.jpmens.net TXT
  ;; ANSWER SECTION:
  94034.zipde.jpmens.net.	604800	IN	TXT	"Passau"
  
  • Florian blames me became inspired by what we all did here, and he built a zone which currently holds 200,000 entries in PowerDNS with UN/LOCODE. Florian and his colleagues use these codes to name anycast instances of k-root as IATA codes are too coarse for their purposes.
  $ dig +short nl-ams.locode.sha256.net LOC
  52 24 0.000 N 4 49 0.000 E 0.00m 1m 10000m 10m

  $ dig +short nl-ams.locode.sha256.net TXT
  "Amsterdam, NL"
  

All these zones we speak of here are DNSSEC signed.

DNS and ansible :: 04 Oct 2020 :: e-mail