├── tests ├── inventory └── test.yml ├── vars └── main.yml ├── handlers └── main.yml ├── tasks ├── global-setup.yml ├── main.yml ├── register-runner.yml ├── install-debian.yml └── install-redhat.yml ├── meta └── main.yml ├── defaults └── main.yml ├── .travis.yml ├── templates └── runner_gitlab-ci-multi-runner.repo.j2 ├── LICENSE └── README.md /tests/inventory: -------------------------------------------------------------------------------- 1 | localhost -------------------------------------------------------------------------------- /vars/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # vars file for gitlab-runner 3 | -------------------------------------------------------------------------------- /handlers/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # handlers file for gitlab-runner 3 | -------------------------------------------------------------------------------- /tests/test.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | remote_user: root 4 | roles: 5 | - ansible-gitlab-runner 6 | -------------------------------------------------------------------------------- /tasks/global-setup.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Set concurrent option 3 | lineinfile: 4 | dest: /etc/gitlab-runner/config.toml 5 | regexp: ^concurrent = 6 | line: concurrent = {{ gitlab_runner_concurrent }} 7 | state: present 8 | -------------------------------------------------------------------------------- /meta/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | galaxy_info: 3 | author: Harold Barker 4 | description: GitLab Runner 5 | license: MIT 6 | min_ansible_version: 2.0 7 | platforms: 8 | - name: EL 9 | versions: 10 | - all 11 | - name: Ubuntu 12 | versions: 13 | - all 14 | - name: Debian 15 | version: 16 | - all 17 | galaxy_tags: 18 | - development 19 | dependencies: [] 20 | -------------------------------------------------------------------------------- /tasks/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Install GitLab Runner (Debian) 3 | include: install-debian.yml 4 | when: ansible_os_family == 'Debian' 5 | 6 | - name: Install GitLab Runner (RedHat) 7 | include: install-redhat.yml 8 | when: ansible_os_family == 'RedHat' 9 | 10 | - name: Set global options 11 | include: global-setup.yml 12 | 13 | - name: Register GitLab Runner 14 | include: register-runner.yml 15 | when: gitlab_runner_registration_token != '' 16 | -------------------------------------------------------------------------------- /defaults/main.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Maximum number of jobs to run concurrently 3 | gitlab_runner_concurrent: '{{ ansible_processor_cores }}' 4 | 5 | # GitLab coordinator URL 6 | gitlab_runner_coordinator_url: 'https://gitlab.com/ci' 7 | # GitLab registration token 8 | gitlab_runner_registration_token: '' 9 | # Runner description 10 | gitlab_runner_description: '{{ ansible_hostname }}' 11 | # Runner executor 12 | gitlab_runner_executor: 'shell' 13 | # Default Docker image 14 | gitlab_runner_docker_image: '' 15 | # Runner tags 16 | gitlab_runner_tags: [] 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | --- 2 | language: python 3 | python: "2.7" 4 | 5 | # Use the new container infrastructure 6 | sudo: false 7 | 8 | # Install ansible 9 | addons: 10 | apt: 11 | packages: 12 | - python-pip 13 | 14 | install: 15 | # Install ansible 16 | - pip install ansible 17 | 18 | # Check ansible version 19 | - ansible --version 20 | 21 | # Create ansible.cfg with correct roles_path 22 | - printf '[defaults]\nroles_path=../' >ansible.cfg 23 | 24 | script: 25 | # Basic role syntax check 26 | - ansible-playbook tests/test.yml -i tests/inventory --syntax-check 27 | 28 | notifications: 29 | webhooks: https://galaxy.ansible.com/api/v1/notifications/ -------------------------------------------------------------------------------- /tasks/register-runner.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: List configured runners 3 | command: gitlab-runner list 4 | register: configured_runners 5 | changed_when: False 6 | 7 | - name: Register runner to GitLab 8 | command: gitlab-runner register > 9 | --non-interactive 10 | --url '{{ gitlab_runner_coordinator_url }}' 11 | --registration-token '{{ gitlab_runner_registration_token }}' 12 | --description '{{ gitlab_runner_description }}' 13 | --tag-list '{{ gitlab_runner_tags | join(",") }}' 14 | --executor '{{ gitlab_runner_executor }}' 15 | --docker-image '{{ gitlab_runner_docker_image }}' 16 | when: configured_runners.stderr.find('\n{{ gitlab_runner_description }}') == -1 17 | -------------------------------------------------------------------------------- /tasks/install-debian.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - name: Add GitLab apt key 3 | apt_key: 4 | url: https://packages.gitlab.com/gpg.key 5 | state: present 6 | 7 | - name: Install GitLab Runner dependencies 8 | apt: 9 | name: '{{ item }}' 10 | state: present 11 | with_items: 12 | - debian-archive-keyring 13 | - apt-transport-https 14 | 15 | - name: Add GitLab Runner apt repo 16 | apt_repository: 17 | repo: 'deb https://packages.gitlab.com/runner/gitlab-ci-multi-runner/{{ ansible_distribution | lower }}/ {{ ansible_distribution_major_version }} main' 18 | state: present 19 | 20 | - name: Install GitLab Runner 21 | apt: 22 | name: gitlab-ci-multi-runner 23 | state: latest 24 | update_cache: yes 25 | -------------------------------------------------------------------------------- /tasks/install-redhat.yml: -------------------------------------------------------------------------------- 1 | --- 2 | 3 | - name: RHEL | Install GitLab GPG key 4 | rpm_key: 5 | state: present 6 | key: https://packages.gitlab.com/gpg.key 7 | when: ansible_os_family == 'RedHat' 8 | tags: 9 | - gitlab 10 | - gitlab-gpg 11 | 12 | - name: Install GitLab Runner dependencies 13 | yum: 14 | name: '{{ item }}' 15 | state: present 16 | with_items: 17 | - pygpgme 18 | - yum-utils 19 | 20 | - name: Add GitLab Runner rpm repo 21 | template: 22 | src: runner_gitlab-ci-multi-runner.repo.j2 23 | dest: /etc/yum.repos.d/runner_gitlab-ci-multi-runner.repo 24 | 25 | - name: Install GitLab Runner 26 | yum: 27 | name: gitlab-ci-multi-runner 28 | state: latest 29 | update_cache: yes 30 | -------------------------------------------------------------------------------- /templates/runner_gitlab-ci-multi-runner.repo.j2: -------------------------------------------------------------------------------- 1 | [runner_gitlab-ci-multi-runner] 2 | name=runner_gitlab-ci-multi-runner 3 | baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/{{ ansible_distribution_major_version }}/$basearch 4 | repo_gpgcheck=1 5 | gpgcheck=0 6 | enabled=1 7 | gpgkey=https://packages.gitlab.com/gpg.key 8 | sslverify=1 9 | sslcacert=/etc/pki/tls/certs/ca-bundle.crt 10 | 11 | [runner_gitlab-ci-multi-runner-source] 12 | name=runner_gitlab-ci-multi-runner-source 13 | baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/{{ ansible_distribution_major_version }}/SRPMS 14 | repo_gpgcheck=1 15 | gpgcheck=0 16 | enabled=1 17 | gpgkey=https://packages.gitlab.com/gpg.key 18 | sslverify=1 19 | sslcacert=/etc/pki/tls/certs/ca-bundle.crt 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Harold Barker 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | GitLab Runner 2 | ============= 3 | 4 | This role will install the [official GitLab Runner](https://gitlab.com/gitlab-org/gitlab-ci-multi-runner) 5 | 6 | Requirements 7 | ------------ 8 | 9 | This role requires Ansible 2.0 or higher. 10 | 11 | 12 | Role Variables 13 | -------------- 14 | 15 | `gitlab_runner_concurrent` 16 | The maximum number of jobs to run concurrently. 17 | Defaults to the number of processor cores. 18 | 19 | `gitlab_runner_registration_token` 20 | The GitLab registration token. If this is specified, a runner will be registered to a GitLab server. 21 | 22 | `gitlab_runner_coordinator_url` 23 | The GitLab coordinator URL. 24 | Defaults to `https://gitlab.com/ci`. 25 | 26 | `gitlab_runner_description` 27 | The description of the runner. 28 | Defaults to the hostname. 29 | 30 | `gitlab_runner_executor` 31 | The executor used by the runner. 32 | Defaults to `shell`. 33 | 34 | `gitlab_runner_docker_image` 35 | The default Docker image to use. Required when executor is `docker`. 36 | 37 | `gitlab_runner_tags` 38 | The tags assigned to the runner, 39 | Defaults to an empty list. 40 | 41 | Dependencies 42 | ------------ 43 | 44 | None 45 | 46 | Example Playbook 47 | ---------------- 48 | ```yaml 49 | - hosts: all 50 | remote_user: root 51 | vars_files: 52 | - vars/main.yml 53 | roles: 54 | - { role: haroldb.gitlab-runner } 55 | ``` 56 | 57 | Inside `vars/main.yml` 58 | ```yaml 59 | gitlab_runner_registration_token: 'HUzTMgnxk17YV8Rj8ucQ' 60 | gitlab_runner_description: 'Example GitLab Runner' 61 | gitlab_runner_tags: 62 | - node 63 | - ruby 64 | - mysql 65 | ``` 66 | 67 | License 68 | ------- 69 | 70 | MIT 71 | --------------------------------------------------------------------------------