Options for Config Files (YAML, TOML, etc)

I’m writing a collection of scripts to do various sysadmin stuff, and I want to include a couple config files, mostly to define things about the local network (the IP/CIDR of the local management/dmz/lan/etc networks for instance). This will allow me to port my scripts between different businesses.

I’m currently looking at using YAML for this. Here’s a quick example:

 ---
Business A: 10.45.32.0/21
  mgmt: 10.45.32.0/23
    clients: 10.45.32.0/24
    servers: 10.45.33.0/24
  dmz: 10.45.34.0/24
  servers: 10.45.35.0/24
  clients: 10.45.36.0/22
    managers: 10.45.34.0/24
    hr: 10.45.35.0/24
    staff: 10.45.36.0/23

So this defines Business A’s main network as 10.45.32.0/21. Within that, there are Management, DMZ, Server and Client subnets. The management subnet is further broken down into client and server management, and clients are broken down into managers, human resources and general staff (again, this is not a real network schema, just an example off the top of my head to illustrate what I need from the config file).

With this info, I can do things like script firewall rules for certain server types. So if I’m configuring an internal wiki for managers (random example), I can grab the managers network info with a script what_is_subnet.sh "clients-managers" and have it spit out 10.45.34.0/24. This would look something like this:

firewall-cmd --permanent --zone=blah --add-source="$(what_is_subnet.sh clients-managers)"
firewall-cmd --permanent --zone=blah --add-port=80/tcp
firewall-cmd --reload

So I’m wondering:

  1. Is YAML a good/bad choice for this? TOML might be better? Does anyone else have a similar use-case? This makes me a little concerned about using YAML.

  2. What’s the best/path-of-least-resistance way of parsing a semi-complex config file like this? Python? Ruby?

toml is nicer to use personally, yaml has this whole formatting with white space thing that I’ve never been a fan of.

1 Like

I am leaning in that direction. What do you use to parse it?

I’ve been using the rust toml crate, works pretty good considering that’s what they use for cargo (their package manager).

1 Like

All I know about Rust is that it’s like a next gen C language (that’s what we’re talking about, right?).

Based on that, I feel like Rust is overkill for reading config into some BASH automation scripts, but maybe not? It would need to be compiled right?

Or is “rust toml crate” a binary that I can just download and use?

Definitely going to go with TOML over YAML.

https://npf.io/2014/08/intro-to-toml/

Having to retype the parent table name for each sub-table is kind of annoying

This is my only complaint.