eugene0707.merge_custom_vars
merge_custom_vars
This tool loads variable files and merges them, combining their content based on a set order of importance. By default, it looks for variable files in the "rpi_vars" folder included in your playbook, with the playbook directory's "rpi_vars" taking priority, and the inventory's "rpi_vars" having the highest priority. You can customize which variable files or folders to merge and their importance.
Requirements
No special requirements are needed to use this.
Role Variables
rpi_dir: The name of the folder where the variable files are located. The default is "rpi_vars".
rpi_files: This is a list of variable files or folders to merge. The order of the items in this list determines their priority. The default order is:
- "{{ rpi_role_dirs }}" - The "rpi_vars" folder from the roles included in your playbook. Roles can be stored within the playbook or in another location specified by the "roles_path" configuration (like "shared" in my case).
- "{{ rpi_playbook_dirs }}" - The "rpi_vars" folder within the playbook itself.
- "{{ rpi_inventory_dirs }}" - The "rpi_vars" folder located in the inventory directory. This is useful if your inventories are in separate folders (as is my setup).
This role does two main things:
- It deeply merges all the data in the specified "rpi_files" (in YAML or JSON format) and saves it to a temporary folder.
- It loads the final merged YAML file using an "include_vars" task.
Dependencies
Requires Ansible version 2 or higher.
Example Playbook
The main idea of this role, beyond merging data, is to create common variables that can be shared across different roles, while allowing for more specific configuration at the playbook and inventory levels. If you're using this role, include it first in your playbook.
Currently, I haven't figured out how to retrieve the vault password using a custom module. However, you can import encrypted variables into the merging process using a lookup plugin, for example:
---
secret:
key: "{{ lookup('file', '{{ playbook_dir }}/files/vault.encrypted.key.txt') }}"
License
GPLv2
Author Information
Evgeniy Kondrashov GitHub Profile
Load vars files with customizable precedence and deep merge hashes within.
ansible-galaxy install eugene0707.merge_custom_vars