Comment 0 for bug 1865969

Revision history for this message
Chad Smith (chad.smith) wrote :

Cloud-init allows user-data to provide a "## template: jinja" header line in user-data in order to render custom cloud-config based on any instance metadata found in /run/cloud-init/instance-data.json.

There are a number of use cases where it would be beneficial to provide unique cloud-config user-data based on what ubuntu release, machine architecture kernel or merged_config default_user you an image may have configured.

Allow cloud customers to write a single cloud-config jinja template which can customize configuration options based on what it's operating environment ends up being.

Add 2 top-level keys to the persisted instance-data.json file:

   merged_cfg: the merged cloud-config from /etc/cloud/cloud.cfg and /etc/cloud/cloud.cfg.d/*cfg
       This merged_cfg is helpful in debug and triage of cloud-init bugs as the filesystem
       images frequently override Ubuntu certified cloud-image defaults.

   sys_info: system platform and distro information surfaced by uname or python.platform.
       This data is already obtained by cloudinit.util.system_info() which is used by
       cloud-init runtime to determine cloud-init behavior on every Ubuntu series and all
       supported distributions.

For ease of use in templates, some of the sys_info fields are generalized as top-level 'v1' standard keys. The following are the new generalized v1 instance data keys:
    distro, distro_release, distro_version, variant
    kernel_release, system_platform, machine, and python_version

This allows a single #cloud-config user-data which would allow for custom cloud-config based on distro details:

  ## template: jinja
  {% if distro_version == 'xenial' %}
    - echo add custom networking extensions to /etc/network/interfaces.d/
  {% elif distro_version == 'bionic' %}
    - echo add my custom networking extensions to /etc/netplan/
  {% elif distro == 'centos' %}
    - echo do something fun with /etc/sysconfig
  {% endif %}