Skip to content

Commit

Permalink
Refactor .exports and .env files
Browse files Browse the repository at this point in the history
  • Loading branch information
smolnar committed Mar 22, 2024
1 parent 09388bd commit 2ce788c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
12 changes: 6 additions & 6 deletions roles/postgresql/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,19 @@
- name: Export PostgreSQL user names as ENV variables
become_user: "{{ user }}"
lineinfile:
dest: ~/.exports
regexp: ^export {{ item | upper }}_DATABASE_USER=
line: export {{ item | upper }}_DATABASE_USER={{ item }}
dest: ~/.env
regexp: '^{{ item | upper }}_DATABASE_USER='
line: '{{ item | upper }}_DATABASE_USER={{ item }}'
state: present
with_items: "{{ users }}"
when: users|length > 0

- name: Export PostgreSQL user passwords as ENV variables
become_user: "{{ user }}"
lineinfile:
dest: ~/.exports
regexp: ^export {{ item | upper }}_DATABASE_PASSWORD=
line: export {{ item | upper }}_DATABASE_PASSWORD="{{ lookup('file', '/tmp/' + item + '.pgpassword') }}"
dest: ~/.env
regexp: "^{{ item | upper }}_DATABASE_PASSWORD="
line: "{{ item | upper }}_DATABASE_PASSWORD={{ lookup('file', '/tmp/' + item + '.pgpassword') }}"
state: present
with_items: "{{ users }}"
when: users|length > 0
6 changes: 3 additions & 3 deletions roles/system/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@
- name: Add NODE_OPTIONS to environment variables
lineinfile:
dest: "~/.exports"
regexp: "^export NODE_OPTIONS="
line: "export NODE_OPTIONS=--openssl-legacy-provider"
dest: "~/.env"
regexp: "^NODE_OPTIONS="
line: "NODE_OPTIONS=--openssl-legacy-provider"
state: present
become_user: "{{ user }}"

Expand Down
13 changes: 7 additions & 6 deletions roles/user/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@
- name: Cleanup old keys
file: path=/tmp/*.authorized_keys state=absent

- name: Setup exports file
- name: Setup global env file
become_user: '{{ user }}'
file:
path: ~/.exports
path: ~/.env
state: touch
group: deploy
mode: 0644

- name: Load exports file in .profile
- name: Load env file in .profile
become_user: '{{ user }}'
lineinfile:
dest: ~/.profile
line: source ~/.exports
line: "export $(cat /home/{{ user }}/.env | xargs)"
insertbefore: EOF
state: present

- name: Load exports file in .bashrc
- name: Load global env file in .bashrc
become_user: '{{ user }}'
lineinfile:
dest: ~/.bashrc
line: source ~/.exports
line: export $(cat /home/{{ user }}/.env | xargs)
insertbefore: BOF
state: present

Expand Down

0 comments on commit 2ce788c

Please sign in to comment.