From 25c40e3fa0101010a14b0e1bd7abe1a47a13bd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A1szl=C3=B3=20Szalma?= Date: Tue, 13 Dec 2016 15:19:56 +0100 Subject: [PATCH] multiple runner at once --- README.md | 8 +++++++- defaults/main.yml | 7 +++++++ tasks/main.yml | 1 - tasks/register-runner.yml | 20 +++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index ef09c49..bed0ee4 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,13 @@ The default Docker image to use. Required when executor is `docker`. The tags assigned to the runner, Defaults to an empty list. -See the [config for more options](https://github.com/riemers/ansible-gitlab-runner/blob/master/tasks/register-runner.yml) +`gitlab_runner_list` +You can add multiple runners in one run. It is a list of dict based on the settings available in one runner. You must set different descriptions for the runners to work. + +# NOTE: +Runners are created for the first time. You can't change the settings of existsing ones with this role. + +See the [config for more options](https://github.com/DBLaci/ansible-gitlab-runner/blob/master/tasks/register-runner.yml) Example Playbook ---------------- diff --git a/defaults/main.yml b/defaults/main.yml index d81d53c..4c07942 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -21,3 +21,10 @@ gitlab_runner_ssh_host: '' gitlab_runner_ssh_port: '' gitlab_runner_ssh_password: '' gitlab_runner_ssh_identity_file: '' + +gitlab_runner_list: + - coordinator_url: 'https://gitlab.com/ci' + registration_token: '' + description: '{{ ansible_hostname }}' + executor: 'shell' + tags: [] diff --git a/tasks/main.yml b/tasks/main.yml index 6d964db..ea2261a 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -12,4 +12,3 @@ - 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 index cc72280..6cfe81f 100644 --- a/tasks/register-runner.yml +++ b/tasks/register-runner.yml @@ -19,4 +19,22 @@ --ssh-port '{{gitlab_runner_ssh_port}}' --ssh-password '{{gitlab_runner_ssh_password}}' --ssh-identity-file '{{gitlab_runner_ssh_identity_file}}' - when: configured_runners.stderr.find('\n{{ gitlab_runner_description }}') == -1 + when: gitlab_runner_registration_token != '' and configured_runners.stderr.find('\n{{ gitlab_runner_description }}') == -1 + +- name: Register multiple runner to GitLab + command: gitlab-runner register > + --non-interactive + --url '{{ item.coordinator_url | d("https://gitlab.com/ci") }}' + --registration-token '{{ item.registration_token }}' + --description '{{ item.description }}' + --tag-list '{{ item.tags | d([]) | join(",") }}' + --executor '{{ item.executor | d("shell") }}' + --docker-image '{{ item.docker_image | d("") }}' + --docker-volumes [ "{{ item.docker_volumes | d([]) | join('", "') }}" ] + --ssh-user '{{ item.ssh_user | d("") }}' + --ssh-host '{{ item.ssh_host | d("") }}' + --ssh-port '{{ item.ssh_port | d("") }}' + --ssh-password '{{ item.ssh_password | d("") }}' + --ssh-identity-file '{{ item.identity_file | d("") }}' + when: configured_runners.stderr.find('\n{{ item.description }}') == -1 + with_items: "{{ gitlab_runner_list }}"