Skip to content

Commit

Permalink
Ensure dir exists. Use variables for user groups.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonpugh authored and jpugh-miax committed Jan 31, 2025
1 parent cf057ea commit 2e4497e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 9 additions & 4 deletions roles/operations.runner/tasks/github.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@
become_user: "{{ item.runner_user | default(operations_platform_user) | default('platform')}}"
set_fact:
# @TODO: Is there a better way to set defaults in a list of maps?
item_runner_path: "{{ user_facts.home }}/{{ item.runner_path | default('runner')}}"
item_runner_path: "{{ user_facts.home }}/{{ item.runner_path | default('runners/' ~ item.runner_repo )}}"
item_runner_user: "{{ item.runner_user | default(operations_platform_user) | default('platform')}}"
item_runner_name: "{{ item.runner_user | default(operations_platform_user) }}@{{ item.runner_name | default(inventory_hostname) }}"
item_runner_repo: "{{ item.runner_repo | default(operations_runner_repo_default) }}"
item_runner_labels: "{{ item.runner_user | default(operations_platform_user) }}@{{ item.runner_name | default(inventory_hostname) }},user/{{ item.runner_user | default(operations_platform_user) | default('platform') }},{{ item.runner_labels | default('') }}"
item_runner_api_token: "{{ item.api_token | default(operations_github_api_token) }}"

- name: Ensure target directory {{ item_runner_path | dirname }} exists
file:
state: directory
path: "{{ item_runner_path | dirname }}"

- name: Copy GitHub Runner
# It will fail if a job is running.
ignore_errors: true
Expand Down Expand Up @@ -50,14 +55,14 @@
failed_when:
- "'token' not in github_runner_registration_token"

- name: "{{ item_runner_repo }} | Remove existing GitHub Runner"
- name: "{{ item_runner_repo }} | Remove existing GitHub Runner from {{ item_runner_path }}"
shell:
cmd: "./svc.sh uninstall"
chdir: "{{ item_runner_path }}"
become: true
ignore_errors: true

- name: "{{ item_runner_repo }} | Setup GitHub Runner"
- name: "{{ item_runner_repo }} | Setup GitHub Runner in {{ item_runner_path }}"
shell:
cmd: "./config.sh remove --token {{ github_runner_registration_token.token }} && ./config.sh --replace --unattended --url {{ item.repo_host | default('https://github.com') }}/{{ item_runner_repo }} --token {{ github_runner_registration_token.token }} --name {{ item_runner_name }} --labels {{ item_runner_labels }}"
chdir: "{{ item_runner_path }}"
Expand All @@ -68,7 +73,7 @@
shell:
cmd: |
whoami
./svc.sh install {{ item_runner_user }}
./svc.sh install {{ item_runner_user }}
./svc.sh start
chdir: "{{ item_runner_path }}"
become: true
2 changes: 2 additions & 0 deletions roles/operations.users/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ operations_admin_users: []

operations_control_user: control
operations_control_home: /var/control
operations_control_user_groups: docker,sudo

operations_platform_user: platform
operations_platform_home: /var/platform
operations_platform_user_groups: docker
4 changes: 2 additions & 2 deletions roles/operations.users/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
shell: /bin/bash
system: true
generate_ssh_key: true
groups: docker
groups: "{{ operations_platform_user_groups }}"

- name: Create Platform home directory
file:
Expand All @@ -34,7 +34,7 @@
user:
name: "{{ operations_control_user }}"
group: "{{ operations_control_user }}"
groups: docker
groups: "{{ operations_control_user_groups }}"
home: "{{ operations_control_home }}"
uid: "{{ operations_control_user_uid | default(omit) }}"
shell: /bin/bash
Expand Down

0 comments on commit 2e4497e

Please sign in to comment.