diff --git a/plays/filter_plugins/filters.py b/plays/filter_plugins/filters.py new file mode 100644 index 0000000..2b6fe46 --- /dev/null +++ b/plays/filter_plugins/filters.py @@ -0,0 +1,21 @@ +#!/usr/bin/env python3 + +"""Custom filters for use in playbooks.""" + + +class FilterModule(object): + """Custom Ansible filter plugins.""" + + def filters(self): + """Filters list.""" + return {"update_env": self.filter_update_env} + + def filter_update_env(self, config, new_env): + """Update the config.env dictionary with new keys.""" + if "env" not in config: + return config + + for key, val in new_env.items(): + config["env"][key] = val + + return config diff --git a/plays/filter_plugins/update_env.py b/plays/filter_plugins/update_env.py deleted file mode 100644 index f798adb..0000000 --- a/plays/filter_plugins/update_env.py +++ /dev/null @@ -1,16 +0,0 @@ -"""Update config.env filter.""" - - -def filter_update_env(config, env): - if config.get("env", False) is False: - return config - - for key, val in env: - config["env"][key] = val - - return config - - -class FilterModule(object): - def filters(self): - return {"update_env": filter_update_env}