Using YAML node anchors for variables in CoreOS configs?

YAML supports a great feature called node anchors. And e.g. Docker compose files make use of that.

Here is a simple example.

Can’t we make use of that in CoreOS files, too?

Resizing the partition root partition could e.g. take an input variable main_disk.

So I tried something like this:

variant: fcos
version: 1.3.0
    main_disk: &main_disk /dev/vda
# ...
    - device: *main_disk
        - label: root
          number: 4
          # 0 means to use all available space
          size_mib: 0
          resize: true

However, it seems we are missing some NOOP-YAML key in the CoreOs spec, as parameters is a key FFCT now complained about:

$ fcct --pretty --strict # […]
Error translating config: yaml: unmarshal errors:
  line 3: field parameters not found in type v1_3.Config

Butane does support YAML anchors (though we don’t document it) but discourages arbitrary fields that aren’t part of the schema. In strict mode the latter will produce errors, as you found, and in non-strict mode they’ll produce warnings. I think it’s fine to use anchors, as long as you’re using them in fields defined by the schema.

But then how could you do that?

You cannot define a template if you have no place where to define those… hmm?

If you’re referencing a value in more than one place, you can use an anchor in the first place, and reference that anchor via an alias in subsequent places.

1 Like