Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Role Variables
- `gitlab_runner_config_update_mode` - Defines how configuration updates are applied:
- Set to `by_config_toml` (default) to apply configuration changes directly by updating the `config.toml` file.
- Set to `by_registering` if changes should be applied by unregistering and re-registering the runner when configuration changes.
- Set to `by_template` if changes for all runners should directly be written in the `config.toml` file. The difference with `by_config_toml` is that this method is faster, but does not take into account the existing configuration of the runners.
- `gitlab_unregister_runner_executors_which_are_not_longer_configured` - Set to `true` if executors should be unregistered from a runner when they are no longer configured in Ansible. Default: `false`.

See the [defaults/main.yml](https://github.com/riemers/ansible-gitlab-runner/blob/master/defaults/main.yml) file for a list of all possible options that can be passed to a runner registration command.
Expand Down
9 changes: 9 additions & 0 deletions tasks/main-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,20 @@

- name: (Container) Set global options
ansible.builtin.import_tasks: global-setup.yml
when: gitlab_runner_config_update_mode == 'by_config_toml' or
gitlab_runner_config_update_mode == 'by_registering'

- name: (Container) Configure GitLab Runner
ansible.builtin.include_tasks: config-runners-container.yml
when: gitlab_runner_config_update_mode == 'by_config_toml'

- name: (Container) Configure Gitlab Runner via template
ansible.builtin.template:
src: config.toml.j2
dest: "{{ gitlab_runner_config_file }}"
mode: "0600"
when: gitlab_runner_config_update_mode == 'by_template'

- name: (Container) Start the container
community.docker.docker_container:
name: "{{ gitlab_runner_container_name }}"
Expand Down
9 changes: 9 additions & 0 deletions tasks/main-unix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,16 @@

- name: Set global options (macOS/Debian/RedHat)
ansible.builtin.import_tasks: global-setup.yml
when: gitlab_runner_config_update_mode == 'by_config_toml' or
gitlab_runner_config_update_mode == 'by_registering'

- name: (Unix) Configure GitLab Runner
ansible.builtin.include_tasks: config-runners.yml
when: gitlab_runner_config_update_mode == 'by_config_toml'

- name: (Unix) Configure Gitlab Runner via template
ansible.builtin.template:
src: config.toml.j2
dest: "{{ gitlab_runner_config_file }}"
mode: "0600"
when: gitlab_runner_config_update_mode == 'by_template'
9 changes: 9 additions & 0 deletions tasks/main-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

- name: (Windows) Set global options
ansible.builtin.import_tasks: global-setup-windows.yml
when: gitlab_runner_config_update_mode == 'by_config_toml' or
gitlab_runner_config_update_mode == 'by_registering'

- name: (Windows) Configure GitLab Runner
ansible.builtin.include_tasks: config-runners-windows.yml
Expand All @@ -39,3 +41,10 @@
args:
chdir: "{{ gitlab_runner_config_file_location }}"
when: gitlab_runner_windows_start_runner

- name: (Windows) Configure Gitlab Runner via template
ansible.builtin.template:
src: config.toml.j2
dest: "{{ gitlab_runner_config_file }}"
mode: "0600"
when: gitlab_runner_config_update_mode == 'by_template'
328 changes: 328 additions & 0 deletions templates/config.toml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,328 @@
concurrent = {{ gitlab_runner_concurrent }}
{% if gitlab_runner_check_interval is defined %}
check_interval = {{ gitlab_runner_check_interval }}
{% endif %}
{% if gitlab_runner_listen_address | length > 0 %}
listen_address = {{ gitlab_runner_listen_address | tojson }}
{% endif %}
{% if gitlab_runner_log_format is defined %}
log_format = {{ gitlab_runner_log_format | default("runner") }}
{% endif %}
{% if gitlab_runner_log_level is defined %}
log_level = {{ gitlab_runner_log_level }}
{% endif %}
{% if gitlab_runner_sentry_dsn | length > 0 %}
sentry_dsn = "{{ gitlab_runner_sentry_dsn }}"
{% endif %}
{% if gitlab_runner_session_server is defined %}
[session_server]
{% if gitlab_runner_session_server.listen_address | length > 0 %}
listen_address = {{ gitlab_runner_session_server.listen_address }}
{% endif %}
{% if gitlab_runner_session_server.advertise_address | length > 0 %}
advertise_address = {{ gitlab_runner_session_server.advertise_address }}
{% endif %}
{% if gitlab_runner_session_server.session_timeout is defined and gitlab_runner_session_server.session_timeout > 0 %}
session_timeout = {{ gitlab_runner_session_server.session_timeout }}
{% endif %}
{% endif %}

{% for gitlab_runner in gitlab_runner_runners %}
[[runners]]
name = {{ gitlab_runner.name | tojson }}
limit = {{ gitlab_runner.concurrent_specific | default(0) }}
url = {{ gitlab_runner.url | default(gitlab_runner_coordinator_url) | tojson }}
{% if gitlab_runner.clone_url is defined %}
clone_url = {{ gitlab_runner.clone_url | tojson }}
{% endif %}
environment = {{ gitlab_runner.env_vars | default([]) | tojson }}
{% if gitlab_runner.pre_get_sources_script is defined %}
pre_get_sources_script = {{ gitlab_runner.pre_get_sources_script | tojson }}
{% endif %}
{% if gitlab_runner.post_get_sources_script is defined %}
post_get_sources_script = {{ gitlab_runner.post_get_sources_script | tojson }}
{% endif %}
{% if gitlab_runner.pre_build_script is defined %}
pre_build_script = {{ gitlab_runner.pre_build_script | tojson }}
{% endif %}
{% if gitlab_runner.tls_ca_file is defined %}
tls-ca-file = {{ gitlab_runner.tls_ca_file | tojson }}
{% endif %}
{% if gitlab_runner.tls_cert_file is defined %}
tls-cert-file = {{ gitlab_runner.tls_cert_file | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.tls_key_file is defined %}
tls-key-file = {{ gitlab_runner.tls_key_file | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.post_build_script is defined %}
post_build_script = {{ gitlab_runner.post_build_script | tojson }}
{% endif %}
executor = {{ gitlab_runner.executor | default("shell") | tojson }}
{% if gitlab_runner.builds_dir is defined %}
builds_dir = {{ gitlab_runner.builds_dir | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_dir is defined %}
cache_dir = {{ gitlab_runner.cache_dir | default("") | tojson }}
{% endif %}
{% if gitlab_runner.shell is defined %}
shell = {{ gitlab_runner.shell | default("") | tojson }}
{% endif %}
output_limit = {{ gitlab_runner.output_limit | default(4096) }}
id = {{ gitlab_runner.id }}
token = {{ gitlab_runner.token | tojson }}
token_obtained_at = {{ gitlab_runner.token_obtained_at }}
token_expires_at = {{gitlab_runner.token_expires_at | default("0001-01-01T00:00:00Z") }}
{#### [runners.docker] section ####}
{% if gitlab_runner.executor == "docker" or gitlab_runner.executor == "docker+machine" %}
[runners.docker]
image = {{ gitlab_runner.docker_image | default("") | tojson }}
{% if gitlab_runner.docker_helper_image is defined %}
helper_image = {{ gitlab_runner.docker_helper_image | default("") | tojson }}
{% endif %}
{% if gitlab_runner.docker_privileged is defined %}
privileged = {{ gitlab_runner.docker_privileged | default(false) | lower }}
{% endif %}
{% if gitlab_runner.docker_wait_for_services_timeout is defined %}
wait_for_services_timeout = {{ gitlab_runner.docker_wait_for_services_timeout | default(30) }}
{% endif %}
{% if gitlab_runner.docker_tls_verify is defined %}
tls_verify = {{ gitlab_runner.docker_tls_verify | default(false) | lower }}
{% endif %}
{% if gitlab_runner.docker_shm_size is defined %}
shm_size = {{ gitlab_runner.docker_shm_size | default(false) | lower }}
{% endif %}
{% if gitlab_runner.docker_disable_cache is defined %}
disable_cache = {{ gitlab_runner.docker_disable_cache | default(false) | lower }}
{% endif %}
{% if gitlab_runner.docker_dns is defined %}
dns = {{ gitlab_runner.docker_dns | default(false) | tojson }}
{% endif %}
{% if gitlab_runner.docker_dns_search is defined %}
dns_search = {{ gitlab_runner.docker_dns_search | default(false) | tojson }}
{% endif %}
{% if gitlab_runner.docker_pull_policy is defined %}
pull_policy = {{ gitlab_runner.docker_pull_policy | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.docker_allowed_pull_policies is defined %}
allowed_pull_policies = {{ gitlab_runner.docker_allowed_pull_policies | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.docker_volumes is defined %}
volumes = {{ gitlab_runner.docker_volumes | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.docker_devices is defined %}
devices = {{ gitlab_runner.docker_devices | default([]) | tojson }}
{% endif %}
{% if gitlab_runner.docker_network_mode is defined %}
network_mode = {{ gitlab_runner.docker_network_mode | default("bridge") | tojson }}
{% endif %}
{% if gitlab_runner.docker_disable_entrypoint_overwrite is defined %}
disable_entrypoint_overwrite = {{ gitlab_runner.docker_disable_entrypoint_overwrite | default(false) | tojson }}
{% endif %}
{% if gitlab_runner.docker_oom_kill_disable is defined %}
oom_kill_disable = {{ gitlab_runner.docker_oom_kill_disable | default(false) | tojson }}
{% endif %}
{% if gitlab_runner.docker_security_opt is defined %}
security_opt = {{ gitlab_runner.docker_security_opt | tojson }}
{% endif %}
{#### [[runners.docker.services]] section ####}
{% if gitlab_runner.docker_services is defined %}
{% for service in gitlab_runner.docker_services %}
[[runners.docker.services]]
{% for attr in service %}
{{ attr }} = {{ service[attr] | to_json }}
{% endfor %}
{% endfor %}
{% endif %}
{% endif %}
{#### [runners.ssh] section #####}
{% if gitlab_runner.executor == "ssh" %}
[runners.ssh]
{% if gitlab_runner.ssh_host is defined %}
host = {{ gitlab_runner.ssh_host | default("") | tojson }}
{% endif %}
{% if gitlab_runner.ssh_user is defined %}
user = {{ gitlab_runner.ssh_user | default("") | tojson }}
{% endif %}
{% if gitlab_runner.ssh_port is defined %}
port = {{ gitlab_runner.ssh_port | default("") | tojson }}
{% endif %}
{% if gitlab_runner.ssh_password is defined %}
password = {{ gitlab_runner.ssh_password | default("") | tojson }}
{% endif %}
{% if gitlab_runner.ssh_identity_file is defined %}
identity_file = {{ gitlab_runner.ssh_identity_file | default("") | tojson }}
{% endif %}
{% endif %}
{#### [runners.virtualbox] section #####}
{% if gitlab_runner.executor == "virtualbox" %}
[runners.virtualbox]
{% if gitlab_runner.virtualbox_base_name is defined %}
base_name = {{ gitlab_runner.virtualbox_base_name | default("") | tojson }}
{% endif %}
{% if gitlab_runner.virtualbox_base_snapshot is defined %}
base_snapshot = {{ gitlab_runner.virtualbox_base_snapshot | tojson }}
{% endif %}
{% if gitlab_runner.virtualbox_base_folder is defined %}
base_folder = {{ gitlab_runner.virtualbox_base_folder | tojson }}
{% endif %}
{% if gitlab_runner.virtualbox_disable_snapshots is defined %}
disable_snapshots = {{ gitlab_runner.virtualbox_disable_snapshots | default(false) | lower }}
{% endif %}
{#### [runners.custom_build_dir] section #####}
{% if gitlab_runner.custom_build_dir_enabled is defined %}
[runners.custom_build_dir]
enabled = {{ gitlab_runner.custom_build_dir_enabled | default(false) | lower }}
{% endif %}
{% endif %}
{#### [runners.cache] section ####}
[runners.cache]
{% if gitlab_runner.cache_type is defined %}
Type = {{ gitlab_runner.cache_type | default("") | to_json }}
{% endif %}
{% if gitlab_runner.cache_path is defined %}
Path = {{ gitlab_runner.cache_path | default("") | to_json }}
{% endif %}
{% if gitlab_runner.cache_shared is defined %}
Shared = {{ gitlab_runner.cache_shared | default("") | lower }}
{% endif %}
{#### [runners.cache.s3] section ####}
{% if gitlab_runner.cache_s3_bucket_name is defined %}
[runners.cache.s3]
BucketName = {{ gitlab_runner.cache_s3_bucket_name | default("") | tojson }}
{% if gitlab_runner.cache_s3_server_address is defined %}
ServerAddress = {{ gitlab_runner.cache_s3_server_address | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_s3_access_key is defined %}
AccessKey = {{ gitlab_runner.cache_s3_access_key | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_s3_secret_key is defined %}
SecretKey = {{ gitlab_runner.cache_s3_secret_key | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_s3_bucket_location is defined %}
BucketLocation = {{ gitlab_runner.cache_s3_bucket_location | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_s3_insecure %}
Insecure = {{ gitlab_runner.cache_s3_insecure | default("") | lower }}
{% endif %}
{% endif %}
{#### [runners.cache.gcs] section ####}
{% if gitlab_runner.cache_gcs_bucket_name is defined %}
[runners.cache.gcs]
BucketName = {{ gitlab_runner.cache_gcs_bucket_name | default("") | tojson }}
{% if gitlab_runner.cache_gcs_credentials_file is defined %}
CredentialsFile = {{ gitlab_runner.cache_gcs_credentials_file | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_gcs_access_id is defined %}
AccessID = {{ gitlab_runner.cache_gcs_access_id | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_gcs_private_key is defined %}
PrivateKey = {{ gitlab_runner.cache_gcs_private_key | default("") | tojson }}
{% endif %}
{% endif %}
{#### [runners.cache.azure] section ####}
{% if gitlab_runner.cache_azure_account_name is defined %}
[runners.cache.azure]
AccountName = {{ gitlab_runner.cache_azure_account_name | default("") | tojson }}
{% if gitlab_runner.cache_azure_account_key is defined %}
AccountKey = {{ gitlab_runner.cache_azure_account_key | default("") | tojson }}
{% endif %}
{% if gitlab_runner.cache_azure_container_name is defined %}
ContainerName = {{ gitlab_runner.cache_azure_container_name | default("") | to_json }}
{% endif %}
{% if gitlab_runner.cache_azure_storage_domain is defined %}
StorageDomain = {{ gitlab_runner.cache_azure_storage_domain | default("") | to_json }}
{% endif %}
{% endif %}
{% if gitlab_runner.feature_flags is defined %}
[runners.feature_flags]
{% for flag in gitlab_runner.feature_flags %}
{{ flag }} = true
{% endfor %}
{% endif %}
{#### [runners.machine] section ####}
{% if gitlab_runner.machine_MachineOptions is defined %}
[runners.machine]
MachineOptions = {{ gitlab_runner.machine_MachineOptions | default("") | tojson }}
{% if gitlab_runner.machine_MaxGrowthRate is defined %}
MaxGrowthRate = {{ gitlab_runner.machine_MaxGrowthRate | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_IdleCount is defined %}
IdleCount = {{ gitlab_runner.machine_IdleCount | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_IdleScaleFactor is defined %}
IdleScaleFactor = {{ gitlab_runner.machine_IdleScaleFactor | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_IdleCountMin is defined %}
IdleCountMin = {{ gitlab_runner.machine_IdleCountMin | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_IdleTime is defined %}
IdleTime = {{ gitlab_runner.machine_IdleTime | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_MaxBuilds is defined %}
MaxBuilds = {{ gitlab_runner.machine_MaxBuilds | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_MachineName is defined %}
MachineName = {{ gitlab_runner.machine_MachineName | default("") | tojson }}
{% endif %}
{% if gitlab_runner.machine_MachineDriver is defined %}
MachineDriver = {{ gitlab_runner.machine_MachineDriver | default("") | tojson }}
{% endif %}
{% endif %}
{#### [runners.autoscaler] section ####}
{% if gitlab_runner.machine_autoscaling is defined %}
[runners.autoscaler]
plugin = "{{ gitlab_runner.autoscaler.plugin }}" # for >= 16.11, ensure you run `gitlab-runner fleeting install` to automatically install the plugin
capacity_per_instance = {{ gitlab_runner.autoscaler.capacity_per_instance }}
max_use_count = {{ gitlab_runner.autoscaler.max_use_count }}
max_instances = {{ gitlab_runner.autoscaler.max_instances }}
[runners.autoscaler.plugin_config]
{% if gitlab_runner.autoscaler.plugin_config.name is defined %}
name = "{{ gitlab_runner.autoscaler.plugin_config.name }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.profile is defined %}
profile = "{{ gitlab_runner.autoscaler.plugin_config.profile }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.config_file is defined %}
config_file = "{{ gitlab_runner.autoscaler.plugin_config.config_file }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.credentials_file is defined %}
credentials_file = "{{ gitlab_runner.autoscaler.plugin_config.credentials_file }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.subscription_id is defined %}
subscription_id = "{{ gitlab_runner.autoscaler.plugin_config.subscription_id }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.resource_group_name is defined %}
resource_group_name = "{{ gitlab_runner.autoscaler.plugin_config.resource_group_name }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.project is defined %}
project = "{{ gitlab_runner.autoscaler.plugin_config.project }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.zone is defined %}
zone = "{{ gitlab_runner.autoscaler.plugin_config.zone }}"
{% endif %}
{% if gitlab_runner.autoscaler.plugin_config.endpoint is defined %}
endpoint = "{{ gitlab_runner.autoscaler.plugin_config.endpoint }}"
{% endif %}
[runners.autoscaler.connector_config]
{% for key, value in gitlab_runner.autoscaler.connector_config.items() %}
{{ key }} = {{ '"' ~ value ~ '"' if value is string else value | lower if value is boolean else value }}
{% endfor %}

{% for policy in gitlab_runner.autoscaler.policies %}
[[runners.autoscaler.policy]]
{% for key, value in policy.items() %}
{{ key }} = {{ '"' ~ value ~ '"' if value is string else value | lower if value is boolean else value }}
{% endfor %}
{% endfor %}
{% endif %}
{#### [[runners.machine.autoscaling]] section ####}
{% if gitlab_runner.machine_autoscaling is defined %}
{% for machine in gitlab_runner.machine_autoscaling %}
[[runners.machine.autoscaling]]
{% for attr in machine %}
{{ attr }} = {{ machine[attr] | to_json }}
{% endfor %}
{% endfor %}
{% endif %}

{% endfor %}