diff --git a/defaults/main.yml b/defaults/main.yml index 5c04e4e7bc680317282a0a443a52b54723fef2c7..93d086911f7133f66f57a87774387189aa431cf5 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,3 +1,14 @@ --- # Maximum number of jobs to run concurrently gitlab_runner_concurrent: '{{ ansible_processor_cores }}' + +# GitLab coordinator URL +gitlab_runner_coordinator_url: 'https://gitlab.com/ci' +# GitLab registration token +gitlab_runner_registration_token: '' +# Runner description +gitlab_runner_description: '{{ ansible_hostname }}' +# Runner executor +gitlab_runner_executor: 'shell' +# Runner tags +gitlab_runner_tags: [] diff --git a/tasks/main.yml b/tasks/main.yml index eb76afeb69556d769f3a343eb229897d0ba2e5da..064596d35060f87150784da081f406e5c4c11d38 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -5,3 +5,7 @@ - name: Set global options include: global-setup.yml + +- name: Register GitLab Runner + include: register-runner.yml + when: gitlab_runner_registration_token != '' diff --git a/tasks/register-runner.yml b/tasks/register-runner.yml new file mode 100644 index 0000000000000000000000000000000000000000..01c0f5caad11b9e6a285509fdae1214aa6435ffc --- /dev/null +++ b/tasks/register-runner.yml @@ -0,0 +1,14 @@ +--- +- name: List configured runners + command: gitlab-runner list + register: configured_runners + +- name: Register runner to GitLab + command: gitlab-runner register > + --non-interactive + --url '{{ gitlab_runner_coordinator_url }}' + --registration-token '{{ gitlab_runner_registration_token }}' + --description '{{ gitlab_runner_description }}' + --tag-list '{{ gitlab_runner_tags | join(",") }}' + --executor '{{ gitlab_runner_executor }}' + when: configured_runners.stderr.find('\n{{ gitlab_runner_description }}') == -1