Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update bashrc and postgres-connection roles #610

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions roles/hxr.postgres-connection/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
pgc_user:
name: "{{ galaxy_user.name }}"
home: "{{ galaxy_user.home }}"
group_name: "{{ galaxy_group.name | default(galaxy_group) }}"
pgc_users:
- uname: "{{ galaxy_user.name }}"
uhome: "{{ galaxy_user.home }}"
gname: "{{ galaxy_group.name | default(galaxy_group) }}"
pguser: "{{ postgres_user }}"
pgpass: "{{ postgres_pass }}"
pgdatabase: galaxy
32 changes: 14 additions & 18 deletions roles/hxr.postgres-connection/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
---
- name: Add env vars in bashrc
lineinfile:
path: "{{ pgc_user.home }}/.bashrc"
regexp: "^export {{ item.var }}"
line: "export {{ item.var }}='{{ item.val }}'"
with_items:
- var: PGUSER
val: "{{ postgres_user }}"
- var: PGHOST
val: "{{ postgres_host }}"
- name: Get all users
getent:
database: passwd
split: ':'

- name: Copy using the 'content' for inline data
copy:
content: |
{{ postgres_host }}:{{ postgres_port }}:*:{{ postgres_user }}:{{ postgres_pass }}
dest: "{{ pgc_user.home }}/.pgpass"
mode: 0600
owner: "{{ pgc_user.name }}"
group: "{{ pgc_user.group_name }}"
- name: Debug info when user does not exist
debug:
msg: "INFO: User {{ item.uname }} does not exist"
loop: "{{ pgc_users }}"
when: (not item.uname in getent_passwd.keys())

- name: Run postgres tasks
include_tasks: postgres_tasks.yml
loop: "{{ pgc_users }}"
when: (item.uname in getent_passwd.keys())
26 changes: 26 additions & 0 deletions roles/hxr.postgres-connection/tasks/postgres_tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: Add postgres connection configuration
block:
- name: Add env vars in bashrc
lineinfile:
path: "{{ item.uhome }}/.bashrc"
regexp: "^export {{ task_item.var }}"
line: "export {{ task_item.var }}='{{ task_item.val }}'"
with_items:
- var: PGUSER
val: "{{ item.pguser }}"
- var: PGHOST
val: "{{ postgres_host }}"
- var: PGDATABASE
val: "{{ item.pgdatabase }}"
loop_control:
loop_var: task_item

- name: Copy using the 'content' for inline data
copy:
content: |
{{ postgres_host }}:{{ postgres_port }}:*:{{ item.pguser }}:{{ item.pgpass }}
dest: "{{ item.uhome }}/.pgpass"
mode: 0600
owner: "{{ item.uname }}"
group: "{{ item.gname }}"
5 changes: 5 additions & 0 deletions roles/usegalaxy-eu.bashrc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
bashrc_users:
- uname: "{{ galaxy_user.name }}"
uhome: "{{ galaxy_user.home }}"
gname: "{{ galaxy_group.name }}"
Loading