Use single filter for filters

This commit is contained in:
Luke Murphy 2020-04-15 13:17:07 +02:00
parent 46c86bdb0e
commit 3a5540df5f
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
2 changed files with 21 additions and 16 deletions

View File

@ -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

View File

@ -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}