Skip to content

[BUG] cannot marshal local-hostname (or variable names with hyphens) #99

@synackd

Description

@synackd

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:

  1. Create test group in SMD (or reuse existing group).
  2. Create the cloud-config above for the test (or existing) SMD group.
  3. Use ochami cloud-init config set -F yaml to apply the group config.
  4. Observe error above.

Expected behavior
There are a few hyphen-separated variables in cloud-init metadata, including:

  • cluster-name
  • local-hostname
  • instance-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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions