Just reporting I ran into this same issue today - the json file complained about certificates, but the yaml file did not. Here was the script I was using for reproduction:
#!/usr/bin/env -S uv run
# /// script
# dependencies = ["pyyaml"]
# ///
import argparse
import tarfile
import io
from pathlib import Path
import json
import yaml
def main() -> None:
p = argparse.ArgumentParser()
p.add_argument("cert", type=Path)
p.add_argument(
"--format",
choices=["json", "yaml"],
default="yaml",
help="Output format for the tar contents",
)
args = p.parse_args()
if not args.cert.is_file():
p.error("certificate must be an existing file")
cert = args.cert.read_text().strip()
if "BEGIN CERTIFICATE" not in cert:
p.error("not a valid PEM certificate")
doc = {
"apply_defaults": True,
"preseed": {
"certificates": [
{
"name": "metasyn",
"type": "client",
"certificate": cert,
}
]
},
}
if args.format == "json":
ext = "json"
data = json.dumps(doc, indent=2).encode()
else:
ext = "yaml"
data = yaml.safe_dump(doc, sort_keys=False).encode()
with tarfile.open("seed.tar", "w") as tar:
# Main config file
info = tarfile.TarInfo(f"incus.{ext}")
info.size = len(data)
tar.addfile(info, io.BytesIO(data))
# Install file (empty)
info = tarfile.TarInfo(f"install.{ext}")
info.size = 0
tar.addfile(info, io.BytesIO(b""))
print(f"Created seed.tar with {args.format.upper()} files!")
if __name__ == "__main__":
main()