Skip to content

Conversation

@joe-usa-amzn
Copy link

@joe-usa-amzn joe-usa-amzn commented Jan 22, 2026

Proposed Commit Message

<feat>(amazon): Create write-metadata module.

Create write-metadata module. This module takes data from the various metadata services and writes them to files.
Add tests for write_metadata module and dictpath utility function

We would like to contribute this module to cloud-init because it is used in EC2 to write DNF vars (/etc/dnf/vars) in Amazon Linux to write region, domain, etc from metadata. It is enabled only for 'amazon' but all distros are able to use this.

Merge type

  • Squash merge using "Proposed Commit Message"
  • [] Rebase and merge unique commits. Requires commit messages per-commit each referencing the pull request number (#<PR_NUM>)

… metadata services and writes them to files.

Add tests for write_metadata module and dictpath utility function
@github-actions github-actions bot added the documentation This Pull Request changes documentation label Jan 22, 2026
@holmanb
Copy link
Member

holmanb commented Jan 22, 2026

Thanks for this proposal @joe-usa-amzn. Some initial questions.

What is this used for on Amazon Linux?

What can this accomplish that cannot be done using a jinja template and instance-data variables?

@holmanb holmanb self-assigned this Jan 22, 2026
@joe-usa-amzn joe-usa-amzn marked this pull request as ready for review January 22, 2026 18:05
@joe-usa-amzn
Copy link
Author

Thanks, checking to see if anything we introduced is duplicative or not.

@blackboxsw
Copy link
Collaborator

blackboxsw commented Jan 23, 2026

Given the examples in tests, it seems like this could be solved by something like:

## template: jinja
#cloud-config
write_files:
  - path: /etc/cloud/region
    content: {{ v1.region }}


# Or filters in jinja which can provide defaults if keys don't exist
write_files:
  - path: /etc/cloud/region
    content: {{ v1.region|default("no region set") }}

# Or conditionals to avoid writing files if you don't have a key
{% if 'region' in v1 %}
write_files:
  - path: /etc/cloud/region
    content: "we've got a region"
{% endif %}

Cloud-init's treatment Jinja syntax and behavior is easily testable on the command line with cloud-init query --format '{{ v1 }} or any other jinja constructs'

@blackboxsw blackboxsw added the incomplete Action required by submitter label Jan 23, 2026
@joe-usa-amzn
Copy link
Author

Right, we found this to work with RHEL 10 with v24.4 so it should technically work on AL (v22.2.2) when we upgrade. This code has been in our "fork" of cloud-init since v19.3.

## template: jinja
#cloud-config
write_files:
- content: |
    {{ ds.meta_data.placement.region }}
  path: /etc/dnf/vars/awsregion
  append: false

@joe-usa-amzn
Copy link
Author

Closing this out as other modules provide the same features.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation This Pull Request changes documentation incomplete Action required by submitter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants