Skip to content

Commit 25582bc

Browse files
Merge pull request #90 from markopolo123/master
[ADD] support custom env files.
2 parents 616c64d + bbf33b4 commit 25582bc

File tree

8 files changed

+171
-13
lines changed

8 files changed

+171
-13
lines changed

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ runner_extra_config_args: ""
103103

104104
# Github repository name
105105
# github_repo: "yourrepo"
106+
107+
# Configuring a custom .env file
108+
# custom_env: |
109+
# http_proxy=YOUR_URL_HERE
110+
# ftp_proxy=YOUR_URL_HERE
111+
# HTTPS_PROXY=YOUR_URL_HERE
112+
# https_proxy=YOUR_URL_HERE
113+
# no_proxy=localhost,127.0.0.1,127.0.0.2
114+
# HTTP_PROXY=
106115
```
107116

108117
## Example Playbook

defaults/main.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ runner_download_repository: "actions/runner"
4343

4444
# Extra arguments to pass to `config.sh`
4545
runner_extra_config_args: ""
46-
4746
# Custom service name when usign Github Enterprise server
4847
# service_name: actions.runner._services.{{ runner_name }}.service
4948

@@ -55,3 +54,12 @@ runner_extra_config_args: ""
5554

5655
# Github repository name
5756
# github_repo: "yourrepo"
57+
58+
# Configuring a custom .env file
59+
# custom_env: |
60+
# http_proxy=YOUR_URL_HERE
61+
# ftp_proxy=YOUR_URL_HERE
62+
# HTTPS_PROXY=YOUR_URL_HERE
63+
# https_proxy=YOUR_URL_HERE
64+
# no_proxy=localhost,127.0.0.1,127.0.0.2
65+
# HTTP_PROXY=

molecule/custom_env/cleanup.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
- name: Cleanup
3+
user: ansible
4+
hosts: all
5+
become: yes
6+
vars:
7+
- runner_user: ansible
8+
- github_repo: ansible-github_actions_runner-testrepo
9+
- github_account: monolithprojects-testorg
10+
- runner_state: absent
11+
roles:
12+
- ansible-github_actions_runner

molecule/custom_env/converge.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
- name: Dev test playbook
3+
user: ansible
4+
hosts: all
5+
gather_facts: yes
6+
become: yes
7+
vars:
8+
- runner_user: ansible
9+
- github_repo: ansible-github_actions_runner-testrepo
10+
- github_account: monolithprojects-testorg
11+
- runner_version: "latest"
12+
- runner_labels:
13+
- label1
14+
- repo-runner
15+
- custom_env: |
16+
# HTTPS_PROXY=YOUR_URL_HERE
17+
18+
roles:
19+
- robertdebock.epel
20+
- ansible-github_actions_runner

molecule/custom_env/molecule.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
provisioner:
3+
name: ansible
4+
config_options:
5+
defaults:
6+
verbosity: 0
7+
playbooks:
8+
converge: converge.yml
9+
cleanup: cleanup.yml
10+
verify: verify.yml
11+
dependency:
12+
name: galaxy
13+
lint: |
14+
yamllint .
15+
ansible-lint .
16+
driver:
17+
name: docker
18+
platforms:
19+
- name: "${os:-ubuntu20}-${tag:-latest}"
20+
image: "${namespace:-monolithprojects}/systemd-${os:-ubuntu20}:${tag:-latest}"
21+
command: /sbin/init
22+
tmpfs:
23+
- /run
24+
- /tmp
25+
volumes:
26+
- /sys/fs/cgroup:/sys/fs/cgroup:ro
27+
privileged: yes
28+
pre_build_image: yes
29+
verifier:
30+
name: ansible
31+
scenario:
32+
name: default
33+
test_sequence:
34+
- dependency
35+
- lint
36+
- destroy
37+
- syntax
38+
- create
39+
- converge
40+
- idempotence
41+
- verify
42+
- cleanup
43+
- destroy

molecule/custom_env/requirements.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
- role: robertdebock.epel
3+
version: 3.0.1

molecule/custom_env/verify.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
- name: validate Repo runners
3+
user: ansible
4+
hosts: all
5+
gather_facts: yes
6+
become: yes
7+
vars:
8+
- runner_user: ansible
9+
- github_repo: ansible-github_actions_runner-testrepo
10+
- github_account: monolithprojects-testorg
11+
- github_api_url: "https://api.github.com"
12+
- access_token: "{{ lookup('env', 'PERSONAL_ACCESS_TOKEN') }}"
13+
- runner_name: ubuntu16-latest
14+
15+
tasks:
16+
- name: Check currently registered runners
17+
uri:
18+
url: "{{ github_api_url }}/repos/{{ github_owner | default(github_account) }}/{{ github_repo }}/actions/runners"
19+
headers:
20+
Authorization: "token {{ access_token }}"
21+
Accept: "application/vnd.github.v3+json"
22+
method: GET
23+
status_code: 200
24+
force_basic_auth: yes
25+
register: registered_runners
26+
27+
- debug:
28+
var: registered_runners.json.runners
29+
30+
- name: Check Runner
31+
assert:
32+
that:
33+
- runner_name in registered_runners.json.runners|map(attribute='name')|list
34+
- registered_runners.json.runners|map(attribute='status') == ["online"]
35+
quiet: true
36+
37+
- name: Check Labels (skipped if labels are OK)
38+
fail:
39+
msg: Woops some labels differ "{{ (registered_runners.json.runners.0 | json_query('labels[*].name') | difference(['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'])) }}"
40+
when: not (registered_runners.json.runners.0 | json_query('labels[*].name') | list ) == (['self-hosted', 'Linux', 'X64', 'label1', 'repo-runner'] | list)
41+
42+
- name: Check custom env file is configured
43+
lineinfile:
44+
dest: /opt/actions-runner/.env
45+
line: "# HTTPS_PROXY=YOUR_URL_HERE"
46+
check_mode: yes
47+
register: presence
48+
failed_when: presence.changed

tasks/install_runner.yml

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
tags:
4242
- install
4343

44-
- name: Create temporary directory for archive
44+
- name: Create temporary directory for archive
4545
file:
4646
path: "{{ runner_pkg_tempdir }}"
4747
state: directory
@@ -56,8 +56,9 @@
5656

5757
- name: Download runner package version - "{{ runner_version }}" (RUN ONCE)
5858
get_url:
59-
url: "https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
60-
actions-runner-linux-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
59+
url:
60+
"https://github.com/{{ runner_download_repository }}/releases/download/v{{ runner_version }}/\
61+
actions-runner-linux-{{ github_actions_architecture }}-{{ runner_version }}.tar.gz"
6162
dest: "{{ runner_pkg_tempdir }}/actions-runner-linux-{{ runner_version }}.tar.gz"
6263
force: no
6364
run_once: yes
@@ -77,10 +78,21 @@
7778
tags:
7879
- install
7980

81+
- name: Configure custom env file if required
82+
blockinfile:
83+
path: "{{ runner_dir }}/.env"
84+
block: "{{ custom_env }}"
85+
owner: "{{ runner_user }}"
86+
mode: 0755
87+
marker_begin: "# BEGIN ANSIBLE MANAGED BLOCK"
88+
marker_end: "# END ANSIBLE MANAGED BLOCK"
89+
when: custom_env is defined
90+
8091
- name: Register runner (if new installation) for repo
81-
command: "{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
82-
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended \
83-
{{ runner_extra_config_args }}"
92+
command:
93+
"{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
94+
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended \
95+
{{ runner_extra_config_args }}"
8496
args:
8597
chdir: "{{ runner_dir }}"
8698
become: yes
@@ -91,8 +103,9 @@
91103
- install
92104

93105
- name: Register runner (if new installation) for organization
94-
command: "{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
95-
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended"
106+
command:
107+
"{{ runner_dir }}/./config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
108+
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended"
96109
args:
97110
chdir: "{{ runner_dir }}"
98111
become: yes
@@ -103,8 +116,9 @@
103116
- install
104117

105118
- name: Replace registered runner for repo
106-
command: "{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
107-
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended --replace"
119+
command:
120+
"{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }}/{{ github_repo }} \
121+
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended --replace"
108122
args:
109123
chdir: "{{ runner_dir }}"
110124
become: yes
@@ -115,8 +129,9 @@
115129
- install
116130

117131
- name: Replace registered runner for organization
118-
command: "{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
119-
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended --replace"
132+
command:
133+
"{{ runner_dir }}/config.sh --url {{ github_url }}/{{ github_owner | default(github_account) }} \
134+
--token {{ registration.json.token }} --name {{ runner_name }} --labels {{ runner_labels | join(',') }} --unattended --replace"
120135
args:
121136
chdir: "{{ runner_dir }}"
122137
become: yes

0 commit comments

Comments
 (0)