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 4 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
3 changes: 3 additions & 0 deletions roles/hxr.postgres-connection/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@ pgc_user:
name: "{{ galaxy_user.name }}"
home: "{{ galaxy_user.home }}"
group_name: "{{ galaxy_group.name | default(galaxy_group) }}"
pguser: "{{ postgres_user }}"
pgpass: "{{ postgres_pass }}"
pgdatabase: galaxy
51 changes: 33 additions & 18 deletions roles/hxr.postgres-connection/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
---
- 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 {{ pgc_user.name }} does not exist"
when: (not pgc_user.name in getent_passwd.keys())

- name: Add postgres connection configuration
block:
- 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: "{{ pguser }}"
- var: PGHOST
val: "{{ postgres_host }}"
- var: PGDATABASE
val: "{{ pgdatabase }}"

- name: Copy using the 'content' for inline data
copy:
content: |
{{ postgres_host }}:{{ postgres_port }}:*:{{ pguser }}:{{ pgpass }}
dest: "{{ pgc_user.home }}/.pgpass"
mode: 0600
owner: "{{ pgc_user.name }}"
group: "{{ pgc_user.group_name }}"
when: (pgc_user.name in getent_passwd.keys())
4 changes: 4 additions & 0 deletions roles/usegalaxy-eu.bashrc/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
user_name: "{{ galaxy_user.name }}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its good to use more specific variable names, to avoid unintended overwriting of other variables and less confusion in the vars files. e.g.

Suggested change
user_name: "{{ galaxy_user.name }}"
bashrc_user_name: "{{ galaxy_user.name }}"

Copy link
Member Author

@sanjaysrikakulam sanjaysrikakulam Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ansible does not support looping over a block

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All tasks in a block should be moved out to another tasks file and then should be included in the main.yml where we can loop. I can implement this since you don't like the idea of invoking the role for every user.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that more, because the variables can stay in a vars file and are not in the playbook. Thank you!

Copy link
Member Author

@sanjaysrikakulam sanjaysrikakulam Feb 21, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the update 3b6594f

I have also updated the example above

user_home: "{{ galaxy_user.home }}"
group_name: "{{ galaxy_group.name }}"
Loading