Skip to content

Commit df721db

Browse files
committed
feat: add environment_file var to allow writing alternative files
Merge branch 'ssteinerX' of https://github.com/ssteinerx/ansible-environment into develop closes #2
2 parents 9ba86f6 + 314ed9c commit df721db

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

README.md

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ $ git clone https://github.com/weareinteractive/ansible-environment.git franklin
3333

3434
Here is a list of all the default variables for this role, which are also available in `defaults/main.yml`.
3535

36+
environment_file: /etc/environment
37+
environment_config:
38+
3639
```
3740
# environment_config:
3841
# LC_ALL: en_US.UTF-8
@@ -48,10 +51,13 @@ environment_config:
4851
roles:
4952
- franklinkim.environment
5053
vars:
54+
environment_file: /some/other/place/.env
5155
environment_config:
5256
LC_ALL: C
5357
```
5458

59+
Default is to work on /env/environment.
60+
5561
## Testing
5662

5763
```

defaults/main.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@
55
# environment_config:
66
# LC_ALL: en_US.UTF-8
77
#
8+
environment_file: /etc/environment
89
environment_config:

tasks/config.yml

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
---
22

3+
- name: Ensure file exists
4+
file: path={{environment_file}} owner=www-data group=www-data state=touch
5+
36
- name: Remove previous values
47
lineinfile:
5-
dest: /etc/environment
8+
dest: "{{ environment_file }}"
69
regexp: '^{{ item.key | upper }}'
710
state: absent
8-
with_dict: environment_config
11+
with_dict: "{{environment_config}}"
912

1013
- name: Configuring environment
1114
lineinfile:
12-
dest: /etc/environment
13-
line: '{{ item.key | upper }}="{{ item.value }}"'
14-
with_dict: environment_config
15+
dest: "{{ environment_file }}"
16+
line: "{{ item.key | upper }}='{{ item.value }}'"
17+
with_dict: "{{environment_config}}"
18+

0 commit comments

Comments
 (0)