Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GitLab Runner
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ansible
Roles
GitLab Runner
Commits
00ec29dc
Commit
00ec29dc
authored
1 year ago
by
jurgenhaas
Browse files
Options
Downloads
Patches
Plain Diff
Add support for auto-registration of runners
parent
cd9e586f
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
tasks/main.yml
+8
-0
8 additions, 0 deletions
tasks/main.yml
templates/register.sh
+12
-2
12 additions, 2 deletions
templates/register.sh
with
20 additions
and
2 deletions
tasks/main.yml
+
8
−
0
View file @
00ec29dc
...
...
@@ -63,4 +63,12 @@
tags
:
-
cron
-
name
:
Auto-register runners for projects
cron
:
name
:
Auto-register runners
job
:
/usr/local/bin/register-gitlab-runner auto > /dev/null 2>&1 && {{ lookup('healthchecks', '', user='root', jobname='Auto-register runners', schedule='* * * * *', disabled=crons_disabled|default(false)) }}
disabled
:
'
{{
crons_disabled|default(false)
}}'
tags
:
-
cron
when
:
not excluded_roles or "gitlab-runner" not in excluded_roles
This diff is collapsed.
Click to expand it.
templates/register.sh
+
12
−
2
View file @
00ec29dc
#!/bin/bash
set
-e
if
[[
"
$1
"
==
""
]]
;
then
echo
"Project ID required as first argument."
exit
1
elif
[[
"
$1
"
==
"auto"
]]
;
then
ID
=
$(
curl
-s
-H
"PRIVATE-TOKEN: {{ gitlab_issue.token }}"
"https://gitlab.lakedrops.com/api/v4/projects/?topic=needs_runner_{{ inventory_hostname }}"
| jq
-r
'.[0].id'
)
if
[[
"
$ID
"
==
"null"
]]
;
then
echo
"Nothing to do"
exit
0
fi
echo
"Adding runner for project ID
$ID
"
curl
-X
PUT
-s
-H
"PRIVATE-TOKEN: {{ gitlab_issue.token }}"
"https://gitlab.lakedrops.com/api/v4/projects/
${
ID
}
"
-d
"topics=runner_{{ inventory_hostname }}"
else
ID
=
$1
fi
ID
=
$1
TOKEN
=
$(
curl
-s
-H
"PRIVATE-TOKEN: {{ gitlab_issue.token }}"
"https://gitlab.lakedrops.com/api/v4/projects/
${
ID
}
"
| jq
-r
.runners_token
)
NAME
=
$(
curl
-s
-H
"PRIVATE-TOKEN: {{ gitlab_issue.token }}"
"https://gitlab.lakedrops.com/api/v4/projects/
${
ID
}
"
| jq
-r
.path_with_namespace
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment