diff options
author | Clément Delafargue <39330590+clementd-fretlink@users.noreply.github.com> | 2020-06-19 11:42:50 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-19 11:42:50 +0200 |
commit | 18c278e2d8f19fe1066908bd6bc631bdb8472333 (patch) | |
tree | 9aea4bc0fbeec80e6e72fcf038fa30873bb2d3cb | |
parent | d5c5bf88290ffb2fbb7835dcfb9c645563cdd3e6 (diff) | |
parent | d5b5cb172cd488883e2eac0395dbe4d34ddd7a44 (diff) | |
download | ansible-clever-18c278e2d8f19fe1066908bd6bc631bdb8472333.tar.gz ansible-clever-18c278e2d8f19fe1066908bd6bc631bdb8472333.tar.zst ansible-clever-18c278e2d8f19fe1066908bd6bc631bdb8472333.zip |
Merge pull request #64 from clementd-fretlink/json-env
Use JSON import for environment variables
-rw-r--r-- | defaults/main.yml | 1 | ||||
-rw-r--r-- | filter_plugins/env_json_map.py | 8 | ||||
-rw-r--r-- | tasks/deploy.yml | 2 | ||||
-rw-r--r-- | tasks/environment.yml | 10 | ||||
-rw-r--r-- | templates/env.j2 | 12 |
5 files changed, 23 insertions, 10 deletions
diff --git a/defaults/main.yml b/defaults/main.yml index dcf9650..bd3b6a6 100644 --- a/defaults/main.yml +++ b/defaults/main.yml | |||
@@ -7,6 +7,7 @@ clever_app_confdir: "{{ clever_app_root }}/.clever_cloud" | |||
7 | clever_login_file: "{{ clever_app_confdir }}/login" | 7 | clever_login_file: "{{ clever_app_confdir }}/login" |
8 | 8 | ||
9 | clever_haskell_entry_point: "{{ clever_entry_point | default(None) }}" | 9 | clever_haskell_entry_point: "{{ clever_entry_point | default(None) }}" |
10 | clever_haskell_env: {} | ||
10 | clever_env: {} | 11 | clever_env: {} |
11 | 12 | ||
12 | clever_disable_metrics: false | 13 | clever_disable_metrics: false |
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 | |||
3 | class 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()] | ||
diff --git a/tasks/deploy.yml b/tasks/deploy.yml index 4d4ecaa..751d78f 100644 --- a/tasks/deploy.yml +++ b/tasks/deploy.yml | |||
@@ -17,7 +17,7 @@ | |||
17 | CONFIGURATION_FILE: "{{ clever_login_file }}" | 17 | CONFIGURATION_FILE: "{{ clever_login_file }}" |
18 | 18 | ||
19 | - name: Push Environment | 19 | - name: Push Environment |
20 | shell: "clever env import < {{ clever_app_confdir }}/env" | 20 | shell: "clever env import --json < {{ clever_app_confdir }}/env" |
21 | args: | 21 | args: |
22 | chdir: "{{ clever_app_root }}" | 22 | chdir: "{{ clever_app_root }}" |
23 | environment: | 23 | environment: |
diff --git a/tasks/environment.yml b/tasks/environment.yml index 1508ad4..60b31d2 100644 --- a/tasks/environment.yml +++ b/tasks/environment.yml | |||
@@ -1,3 +1,13 @@ | |||
1 | - name: Setup haskell-specific environment variables | ||
2 | set_fact: | ||
3 | clever_haskell_env: | ||
4 | CC_RUN_COMMAND: "~/.local/bin/{{ clever_haskell_entry_point }}" | ||
5 | when: clever_haskell_entry_point is defined | ||
6 | |||
7 | - name: Assemble full environment | ||
8 | set_fact: | ||
9 | clever_env: "{{ clever_base_env | combine(clever_haskell_env) | combine(clever_env) }}" | ||
10 | |||
1 | - name: Create environment file | 11 | - name: Create environment file |
2 | template: | 12 | template: |
3 | src: env.j2 | 13 | src: env.j2 |
diff --git a/templates/env.j2 b/templates/env.j2 index 30bda82..59f3050 100644 --- a/templates/env.j2 +++ b/templates/env.j2 | |||
@@ -1,9 +1,3 @@ | |||
1 | {% for key, value in (clever_base_env | combine(clever_env)).items() %} | 1 | {# dict2items is not enough here, all the values have to be stringified #} |
2 | {{ key }}={{ value | to_json }} | 2 | {# git-blame this line for more explanations #} |
3 | {% endfor %} | 3 | {{ clever_env | json_env_map | to_json }} |
4 | |||
5 | {%- if clever_haskell_entry_point %} | ||
6 | {# Haskell only #} | ||
7 | {# https://www.clever-cloud.com/doc/get-help/reference-environment-variables/#haskell #} | ||
8 | CC_RUN_COMMAND={{'~/.local/bin/' + clever_haskell_entry_point | to_json }} | ||
9 | {% endif %} | ||