-
Notifications
You must be signed in to change notification settings - Fork 5
Description
Describe the bug
Attempting to use the local-hostname Jinja2 variable (or other hyphen-separated variable) in a cloud-config YAML payload fails because the hyphen is treated as an operator.
For example, given the following cloud-init config payload for the 'test' group:
---
- name: test
description: "test group config"
meta-data:
my_data:
de01: testdata
file:
encoding: plain
content: |
## template: jinja
#cloud-config
{% set ns = namespace(f = ds.meta_data.instance_data.v1.vendor_data.groups.my_data) -%}
write_files:
- path : /etc/hostdata
owner: root:root
permissions: '0600'
encoding: base64
content: '{{ ns.f.my_data[ds.meta_data.local-hostname] }}'When attempting to add this to cloud-init (e.g. with ochami cloud-init group set -F yaml -d @file.yaml), the following error occurs:
unable to evaluate ns.f.my_data[ds.meta_data.local - hostname]: Can't access an index on type map (variable )"
Referencing cloud-init variables containing hyphens errs.
To Reproduce
Steps to reproduce the behavior:
- Create
testgroup in SMD (or reuse existing group). - Create the cloud-config above for the
test(or existing) SMD group. - Use
ochami cloud-init config set -F yamlto apply the group config. - Observe error above.
Expected behavior
There are a few hyphen-separated variables in cloud-init metadata, including:
cluster-namelocal-hostnameinstance-id
that are alongside underscore-separated variables (instance_data, vendor_data, local_ipv4, etc.). These variable names should be consistent, and my proposition is to make all variables underscore-separated so as to avoid conflict with all data formats.
Environment:
- OS: Rocky Linux 9
- cloud-init v1.3.0 (from OpenCHAMI release v0.1.1)
Additional context
N/A