mirror of
https://github.com/KevinMidboe/playbooks-retailor.git
synced 2026-09-07 13:32:06 +00:00
better handling when parsing env into dict
This commit is contained in:
Vendored
+7
-3
@@ -1,12 +1,16 @@
|
|||||||
---
|
---
|
||||||
- name: Read .env file
|
- name: Read .env file
|
||||||
ansible.builtin.slurp:
|
ansible.builtin.slurp:
|
||||||
src: "../.env"
|
src: "{{ playbook_dir }}/../.env"
|
||||||
delegate_to: localhost
|
delegate_to: localhost
|
||||||
register: env_file
|
register: env_file
|
||||||
|
|
||||||
- name: Parse .env file
|
- name: Build list of key/value pairs
|
||||||
ansible.builtin.set_fact:
|
ansible.builtin.set_fact:
|
||||||
env_vars: "{{ dict(env_file['content'] | b64decode | split('\n') | select('search', '=') | map('split', '=', 1) | list) }}"
|
env_lines: "{{ (env_file['content'] | b64decode).splitlines() | select('match', '^[^#=]+=.*$') | list }}"
|
||||||
|
|
||||||
|
- name: Parse .env file into a dict
|
||||||
|
ansible.builtin.set_fact:
|
||||||
|
env_vars: "{{ env_vars | default({}) | combine({ (item.split('=', 1)[0] | trim): (item.split('=', 1)[1] | trim) }) }}"
|
||||||
|
loop: "{{ env_lines }}"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user