aboutsummaryrefslogtreecommitdiffhomepage
path: root/filter_plugins
diff options
context:
space:
mode:
authorClement Delafargue <clement.delafargue@fretlink.com>2020-06-18 16:09:46 +0200
committerClement Delafargue <clement.delafargue@fretlink.com>2020-06-19 10:18:47 +0200
commit244339e70a1be830ac02306e1feb4383fe73572b (patch)
tree96f1b623c151d32d9d0418a9dfc9c45695a2bd41 /filter_plugins
parentd5c5bf88290ffb2fbb7835dcfb9c645563cdd3e6 (diff)
downloadansible-clever-244339e70a1be830ac02306e1feb4383fe73572b.tar.gz
ansible-clever-244339e70a1be830ac02306e1feb4383fe73572b.tar.zst
ansible-clever-244339e70a1be830ac02306e1feb4383fe73572b.zip
Use JSON import for environment variables
The env can be provided as a JSON list `[{"name": "PORT", "value": "8080"}]`. The `dict2items` filter provided by ansible is _almost_ what we want, but it keeps the value original types (a boolean is kept as a boolean in the JSON value). Since environment variables are strings and `clever-tools` does not want to make the implicit coercion for us, we need to do it ourselves.
Diffstat (limited to 'filter_plugins')
-rw-r--r--filter_plugins/env_json_map.py8
1 files changed, 8 insertions, 0 deletions
diff --git a/filter_plugins/env_json_map.py b/filter_plugins/env_json_map.py
new file mode 100644
index 0000000..790dea0
--- /dev/null
+++ b/filter_plugins/env_json_map.py
@@ -0,0 +1,8 @@
1#!/usr/bin/env python
2
3class FilterModule(object):
4 def filters(self):
5 return {'json_env_map': self.json_env_map}
6
7 def json_env_map(self, env):
8 return [{'name': k, 'value': str(v)} for k,v in env.items()]