codeaffen.hieradata.hieradata – Loads configuration from a hierarchical configuration structure

Note

This plugin is part of the codeaffen.hieradata collection (version 0.1.0).

To install it use: ansible-galaxy collection install codeaffen.hieradata.

To use it in a playbook, specify: codeaffen.hieradata.hieradata.

New in version 0.0.1: of codeaffen.hieradata

Synopsis

  • Loads YAML vars into corresponding hierarchy directories/files.

  • Loads only files with extension to one of .yaml, .json, .yml or no extension.

  • Starting in 0.0.1, this plugin requires explicit whitelisting via vars_plugins_enabled.

Requirements

The below requirements are needed on the local controller node that executes this vars.

  • whitelist in configuration

Parameters

Parameter Choices/Defaults Configuration Comments
_valid_extensions
list / elements=string
Default:
[".yml", ".yaml", ".json"]
ini entries:

[yaml_valid_extensions]
defaults = ['.yml', '.yaml', '.json']

env:ANSIBLE_YAML_FILENAME_EXT
Check all of these extensions when looking for 'variable' files which should be YAML or JSON or vaulted versions of these.
This affects vars_files, include_vars, inventory and vars plugins among others.
basedir
string
Default:
"hieradata"
ini entries:

[hieradata]
basedir = hieradata

env:HIERADATA_BASE_DIR
The base directory where the hierarchy has to be placed in.
The base directory has to be placed within the inventory directory or playbook directory.
config
string
Default:
"hieradata.yml"
ini entries:

[hieradata]
config = hieradata.yml

env:HIERADATA_CONFIG_FILE
Name of hieradata configuration file.
The hieradata configuration file has to be placed within the inventory dirctory or playbook directory.
hash_behavior
string
    Choices:
  • merge ←
  • replace
ini entries:

[hieradata]
hash_behavior = merge

env:HIERADATA_HASH_BEHAVIOR
This setting defines how hashes will be merged.
By default hieradata will merge hashes, so data only exists in higher precedence will be added to the data with lower precedence.
Higher precedence value will override lower precedence values.
You can define replace if you want to override data with lower precedence.
list_behavior
string
    Choices:
  • append
  • append_rp
  • keep
  • prepend
  • prepend_rp
  • replace ←
ini entries:

[hieradata]
list_behavior = replace

env:HIERADATA_HASH_BEHAVIOR
This setting defines how lists will be handled.
By default data with higher precedence will `replace` data with lower precedence.
You can also append or prepend data with higher precedence.
With replace you can override data with lower precedece by data with higher one.
stage
string
added in 2.10 of ansible.builtin
    Choices:
  • all
  • task
  • inventory
ini entries:

[hieradata]
stage = None

env:HIERADATA_VARS_PLUGIN_STAGE
Control when this vars plugin may be executed.
Setting this option to all will run the vars plugin after importing inventory and whenever it is demanded by a task.
Setting this option to task will only run the vars plugin whenever it is demanded by a task.
Setting this option to inventory will only run the vars plugin after parsing inventory.
If this option is omitted, the global RUN_VARS_PLUGINS configuration is used to determine when to execute the vars plugin.

Examples

# hieradata.yml.
# Each level in hierarchy can be a file or a directory.
hiera_vars:
  role: "{{ entity.name.split('-').0 }}"
  env: "{{ entity.name.split('-').2 }}"
hierarchy:
  - common
  - "{{ env }}"
  - "{{ role }}"
  - "{{ role }}-{{ env }}"

# hieradata organized with sub directories.
# Last part of path of each level can be a file or a directory.
hiera_vars:
  role: "{{ entity.name.split('-').0 }}"
  env: "{{ entity.name.split('-').2 }}"
hieradata:
  hierarchy:
    - common
    - "environments/{{ env }}"
    - "roles/{{ role }}"
    - "roles/{{ role }}-{{ env }}"