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

feat: add options for UID and GID #36

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Set up (the latest version of) [RStudio Connect](https://www.rstudio.com/product
* `rstudio_connect_config`: A map of maps containing RStudio Connect configuration. Gets converted into Golang's configuration file (GCFG) and is writted on down to `rstudio-connect.gcfg`. See [default](./defaults/main.yml) for an example.
* `rstudio_connect_config_override` [default: `""`]: If you know what you're doing, you can override whole `rstudio-connect.gcfg` config.
* `rstudio_connect_license`: If specified, RStudio Connect will attempt to activate the supplied license key.
* `rstudio_connect_user_id` [default: undefined]: Set user id of `rstudio-connect` user to the provided value after Connect installation. Helps with keeping a consistent UID.
* `rstudio_connect_group_id` [default: undefined]: Set group id of `rstudio-connect` user to the provided value after Connect installation. Helps with keeping a consistent GID.
* `rstudio_connect_python_executables` [default: `[]`]: List of paths to Python executables (e.g. `[/opt/python/3.10.6/bin/python3]`).
* `python_versions` [default: `[]`]: List of Python versions, which were installed with [ansible-python-install role](https://github.com/Appsilon/ansible-python-install) (e.g. `[3.10.6, 3.7.8]`). Role will append Python executables information to the RStudio Connect configuration (using pattern: `/opt/python/x.x.x/bin/python3`).

Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ rstudio_connect_sso_saml_metadata_content_b64_encoded: ""
rstudio_encryption_key: ""
rstudio_connect_encryption_key_location: "/var/lib/rstudio-connect/db/secret.key"

# rstudio_connect_user_id: 933
# rstudio_connect_group_id: 933

rstudio_connect_config:
HTTP:
Listen: :{{ rstudio_connect_www_port }}
Expand Down
18 changes: 18 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,24 @@
tags:
- rstudio-connect-configure-environment-file

- name: Get rstudio-connect user info
ansible.builtin.getent:
database: passwd
key: "rstudio-connect"

- name: Extract UID and GID
ansible.builtin.set_fact:
connect_uid: "{{ getent_passwd['rstudio-connect'][1] }}"
connect_gid: "{{ getent_passwd['rstudio-connect'][2] }}"

- name: Include user tasks
ansible.builtin.include_tasks: user.yml
when: >
(rstudio_connect_user_id is defined and rstudio_connect_user_id != (connect_uid | int))
or (rstudio_connect_group_id is defined and rstudio_connect_group_id != (connect_gid | int))
tags:
- rstudio-connect-configure-user

- name: Include license tasks
ansible.builtin.include_tasks: license.yml
tags:
Expand Down
26 changes: 26 additions & 0 deletions tasks/user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
- name: User | Stop rstudio-connect
ansible.builtin.service:
name: rstudio-connect
state: stopped

- name: User | Change UID
ansible.builtin.user:
name: "{{ rstudio_connect_user }}"
uid: "{{ rstudio_connect_user_id }}"
when:
- rstudio_connect_user_id is defined
- rstudio_connect_user_id > 0

- name: User | Change GID
ansible.builtin.group:
name: "{{ rstudio_connect_user }}"
gid: "{{ rstudio_connect_group_id }}"
when:
- rstudio_connect_group_id is defined
- rstudio_connect_group_id > 0

- name: User | Start rstudio-connect
ansible.builtin.service:
name: rstudio-connect
state: started
22 changes: 22 additions & 0 deletions tests/tasks/verify-common.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,25 @@
status_code:
- 200
- 402

- name: Verify (Common) | Get rstudio-connect user info
ansible.builtin.getent:
database: passwd
key: "rstudio-connect"

- name: Verify (Common) | Extract UID and GID
ansible.builtin.set_fact:
connect_uid: "{{ getent_passwd['rstudio-connect'][1] }}"
connect_gid: "{{ getent_passwd['rstudio-connect'][2] }}"

- name: Verify (Common) | Check UID
ansible.builtin.assert:
that:
- (connect_uid | int) == 933
fail_msg: "UID is not valid. UID from passwd {{ connect_uid }}"

- name: Verify (Common) | Check GID
ansible.builtin.assert:
that:
- (connect_gid | int) == 944
fail_msg: "GID is not valid. GID from passwd {{ connect_gid }}"
1 change: 1 addition & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ rstudio_connect_machine_map:
i386: i386
x86_64: amd64
amd64: amd64
rstudio_connect_user: "rstudio-connect"
Loading