Cloud-init validator
Asked Answered
D

3

20

Wondering if anyone knows of a validator that can validate cloud-init config similar to this. We tried it and it gives a bunch of errors that are not applicable e.g., it does not recognize package_update which is a standard keyword that can be found here in the official documentation for example. So we are looking for a validator that works and recognizes the keywords in the official documentation.

enter image description here

Disembowel answered 29/1, 2019 at 18:11 Comment(0)
M
35

I hit this one recently too and found a nice way to do it.

In Ubuntu you can use the follwoing to validate the file parses correctly.

cloud-init schema --config-file bob.txt

This will give you the following notice if the files are valid or invalid

:~$ sudo cloud-init schema --config-file bob.txt
Valid cloud-config file bob.txt

$ nano bob.txt #edited the yaml to make it invalid
:~$ sudo cloud-init schema --config-file bob.txt
Cloud config schema errors: format-l2.c1: File bob.txt is not valid yaml. while parsing a block mapping
  in "<byte string>", line 2, column 1:
    package_upgrade: true
    ^
expected <block end>, but found '-'
  in "<byte string>", line 6, column 1:
    - 'curl -fsSL https://get.docker ... 
    ^

While your working with cloud init files cloud-init status --wait and many of the other commands on the cli are super useful.

Mingy answered 31/1, 2019 at 17:49 Comment(3)
This errors on v22.2-0ubuntu1~20.04.3: /usr/bin/cloud-init devel: error: argument subcommand: invalid choice: 'schema' (choose from 'hotplug-hook', 'net-convert', 'render', 'make-mime')Honeydew
Is there any convenient way to install it locally on MacOS? Don't see it on brew.Overnight
no cloud-init on alma neitherTardigrade
T
8

Starting from version 22.2, the cloud-init command to validate config file is now:

cloud-init schema --config-file conf.yaml
Teepee answered 21/7, 2022 at 11:57 Comment(0)
C
0

If you are on an older version of cloud-init you may need to use:

cloud-init devel schema --config-file .yaml

Caritacaritas answered 6/9, 2023 at 15:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.