Create an environment that stores default relative paths for role templates/files #3
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
It would be ideal to define some variables for the execution environment of our Ansible playbooks and roles, that define the expected relative paths within
$SKATO_ANSIBLE_ROOT/roles/*/{templates,files}/for finding specific kinds of configuration files or data necessary for role tasks/handlers or Ansible plays.A possibility is storing these paths in a
.envfile under$SKATO_ANSIBLE_ROOT/, that is sourced by the shell and contains, e.g.:Then, the hard-coded paths to the Ansible role templates or files in tasks or handlers that use the
community.general.copyorcommunity.general.templateAnsible modules will be replaced with paths that make use of, i.e. incorporate, these environment variables.This would allow the user of these Ansible roles / plays to change the directory structure within which certain things are found, without breaking the working code.
This is just an example implementation--there may be better ways or ways that actually work (there is no guarantee that placing environment variables in Ansible YAML files will actually have them be evaluated by the local shell--would need to some research to know).
Apparently, the Ansible documentation mentions a
lookupJinja/Python function plugin,ansible.builtin.envon this page: https://docs.ansible.com/projects/ansible/latest/collections/ansible/builtin/env_lookup.htmlThis may be useful for implementing an execution environment containing the relative paths of role templates/files.
Created a script recently that also exports environment variables for paths relevant to
skato-ansibleproject: .bin/skansible.shThat said, this doesn't really allow use of
ansible.builtin.envforlookupJinja/Python function plugin as mentioned previously, at least until after the${SKATO_ANSIBLE_ROOT}/.bin/skansible.shhas been executed. This can be ensured by requiring the user use that script to interface withansible-playbook,ansible-vault, andansible-galaxyvia its native functions, rather than calling those commands directly in the shell.Given the need to manipulate certain parts of our YAML files when updating, for example, the GPG keys of/for certain users created or to be created by our Ansible playbooks (or our Ansible
bootstraprole), among other things, it might be best to transition to implementing a CLI tool using the Python Click package/library.Decided on creating a Python app that handles interface with the environment. An INI file may be used but may otherwise be unnecessary for path variables in particular, as they can be defined in or for relevant classes for or in the Python app itself. This means maintaining consistency where needed when attempting changes or additions will not be a burden for the user, but will be handled "programmatically."