Skip to content

Commit

Permalink
Merge pull request #219 from putsev/add_counters_in_names
Browse files Browse the repository at this point in the history
Add counters in names of tasks, whose are called from loops
  • Loading branch information
riemers authored Dec 12, 2021
2 parents 2efe8a6 + 9614c21 commit c8cfe5f
Show file tree
Hide file tree
Showing 17 changed files with 141 additions and 112 deletions.
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ gitlab_runner_restart_state: restarted
# default value for log_format
# gitlab_runner_log_format: runner

# controls diffs for assemle config file
gitlab_runner_show_config_diff: no

# A list of runners to register and configure
gitlab_runner_runners:
# The identifier of the runner.
Expand Down
4 changes: 2 additions & 2 deletions tasks/Container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@

- name: configured_runners?
debug:
msg: "{{configured_runners.container.Output}}"
msg: "{{ configured_runners.container.Output }}"

- name: verified_runners?
debug:
msg: "{{verified_runners.container.Output}}"
msg: "{{ verified_runners.container.Output }}"

- name: (Container) Register GitLab Runner
include_tasks: register-runner-container.yml
Expand Down
8 changes: 5 additions & 3 deletions tasks/config-runner-container.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Create temporary file
- name: "{{ conf_name_prefix }} Create temporary file"
tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
Expand All @@ -8,14 +8,16 @@
check_mode: no
changed_when: false

- name: Isolate runner configuration
- name: "{{ conf_name_prefix }} Isolate runner configuration"
copy:
dest: "{{ temp_runner_config.path }}"
content: "{{ runner_config }}"
check_mode: no
changed_when: false

- include_tasks: update-config-runner.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
when:
- ('name = "'+gitlab_runner.name|default(ansible_hostname+'-'+gitlab_runner_index|string)+'"') in runner_config
- gitlab_runner.state|default('present') == 'present'
Expand All @@ -24,7 +26,7 @@
index_var: gitlab_runner_index
loop_var: gitlab_runner

- name: Remove runner config
- name: "{{ conf_name_prefix }} Remove runner config"
file:
path: "{{ temp_runner_config.path }}"
state: absent
Expand Down
8 changes: 5 additions & 3 deletions tasks/config-runner-windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: (Windows) Create temporary file
- name: "(Windows) {{ conf_name_prefix }} Create temporary file"
win_tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
Expand All @@ -8,14 +8,16 @@
check_mode: no
changed_when: false

- name: (Windows) Isolate runner configuration
- name: "(Windows) {{ conf_name_prefix }} Isolate runner configuration"
win_copy:
dest: "{{ temp_runner_config.path }}"
content: "{{ runner_config }}"
check_mode: no
changed_when: false

- include_tasks: update-config-runner-windows.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
when:
- ('name = "'+gitlab_runner.name|default(ansible_hostname+'-'+gitlab_runner_index|string)+'"') in runner_config
- gitlab_runner.state|default('present') == 'present'
Expand All @@ -24,7 +26,7 @@
index_var: gitlab_runner_index
loop_var: gitlab_runner

- name: (Windows) Remove runner config
- name: "(Windows) {{ conf_name_prefix }} Remove runner config"
win_file:
path: "{{ temp_runner_config.path }}"
state: absent
Expand Down
9 changes: 6 additions & 3 deletions tasks/config-runner.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: Create temporary file

- name: "{{ conf_name_prefix }} Create temporary file"
tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
Expand All @@ -8,14 +9,16 @@
check_mode: no
changed_when: false

- name: Isolate runner configuration
- name: "{{ conf_name_prefix }} Isolate runner configuration"
copy:
dest: "{{ temp_runner_config.path }}"
content: "{{ runner_config }}"
check_mode: no
changed_when: false

- include_tasks: update-config-runner.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
when:
- ('name = "'+gitlab_runner.name|default(ansible_hostname+'-'+gitlab_runner_index|string)+'"') in runner_config
- gitlab_runner.state|default('present') == 'present'
Expand All @@ -24,7 +27,7 @@
index_var: gitlab_runner_index
loop_var: gitlab_runner

- name: Remove runner config
- name: "{{ conf_name_prefix }} Remove runner config"
file:
path: "{{ temp_runner_config.path }}"
state: absent
Expand Down
4 changes: 3 additions & 1 deletion tasks/config-runners-container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
changed_when: false

- name: Write config section for each runner
vars:
conf_name_prefix: "conf[{{ (runner_config_index|int) + 1 }}/{{ runner_configs|length }}]:"
include_tasks: config-runner-container.yml
loop: "{{ runner_configs }}"
loop_control:
Expand All @@ -31,6 +33,6 @@
backup: yes
validate: |
docker run -i --rm -v %s:/gitlab-runner.conf
{{ gitlab_runner_container_image }}:{{ gitlab_runner_container_tag }}
{{ gitlab_runner_container_image }}:{{ gitlab_runner_container_tag }}
verify -c /gitlab-runner.conf
mode: 0600
2 changes: 2 additions & 0 deletions tasks/config-runners-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
changed_when: false

- name: (Windows) Write config section for each runner
vars:
conf_name_prefix: "conf[{{ (runner_config_index|int) + 1 }}/{{ runner_configs|length }}]:"
include_tasks: config-runner-windows.yml
loop: "{{ runner_configs }}"
loop_control:
Expand Down
3 changes: 3 additions & 0 deletions tasks/config-runners.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
changed_when: false

- name: Write config section for each runner
vars:
conf_name_prefix: "conf[{{ (runner_config_index|int) + 1 }}/{{ runner_configs|length }}]:"
include_tasks: config-runner.yml
loop: "{{ runner_configs }}"
loop_control:
Expand All @@ -33,3 +35,4 @@
validate: "{{ gitlab_runner_executable }} verify -c %s"
mode: 0600
become: "{{ gitlab_runner_system_mode }}"
diff: "{{ gitlab_runner_show_config_diff|bool }}"
2 changes: 1 addition & 1 deletion tasks/global-setup.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
- restart_gitlab_runner
- restart_gitlab_runner_macos

- name: Add log_format to config
- name: Add log_format to config
lineinfile:
dest: "{{ gitlab_runner_config_file }}"
regexp: '^log_format ='
Expand Down
4 changes: 2 additions & 2 deletions tasks/install-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
args:
chdir: "{{ gitlab_runner_config_file_location }}"
when: (gitlab_runner_windows_service_user | length == 0) or (gitlab_runner_windows_service_password | length == 0)

- name: (Windows) Install GitLab Runner
win_command: "{{ gitlab_runner_executable }} install --user \"{{ gitlab_runner_windows_service_user }}\" --password \"{{ gitlab_runner_windows_service_password }}\""
win_command: "{{ gitlab_runner_executable }} install --user \"{{ gitlab_runner_windows_service_user }}\" --password \"{{ gitlab_runner_windows_service_password }}\"" # noqa 204
args:
chdir: "{{ gitlab_runner_config_file_location }}"
when:
Expand Down
4 changes: 2 additions & 2 deletions tasks/line-config-runner-windows.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: (Windows) Ensure section exists
- name: "(Windows) {{ line_name_prefix }} Ensure section exists"
win_lineinfile:
path: "{{ temp_runner_config.path }}"
regexp: '^(\s*)\[{{ section|regex_escape }}\]$'
line: '{{ " " * (section.split(".")|length -1) }}[{{ section }}]'

- name: (Windows) Modify existing line
- name: "(Windows) {{ line_name_prefix }} Modify existing line"
win_lineinfile:
path: "{{ temp_runner_config.path }}"
insertafter: '\s+\[{{ section | regex_escape }}\]'
Expand Down
4 changes: 2 additions & 2 deletions tasks/line-config-runner.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
---
- name: Ensure section exists
- name: "{{ line_name_prefix }} Ensure section exists"
lineinfile:
path: "{{ temp_runner_config.path }}"
regexp: '^(\s*)\[{{ section|regex_escape }}\]$'
line: '{{ " " * (section.split(".")|length -1) }}[{{ section }}]'

- name: Modify existing line
- name: "{{ line_name_prefix }} Modify existing line"
lineinfile:
path: "{{ temp_runner_config.path }}"
insertafter: '\s+\[{{ section | regex_escape }}\]'
Expand Down
3 changes: 3 additions & 0 deletions tasks/section-config-runner-windows.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: line-config-runner-windows.yml
vars:
line_name_prefix: "{{ sect_name_prefix }} line:[{{ (line_index|int) + 1 }}/{{ gitlab_runner.extra_configs[section]|list|length }}]: "
loop: "{{ gitlab_runner.extra_configs[section] | list }}"
loop_control:
loop_var: line
index_var: line_index
3 changes: 3 additions & 0 deletions tasks/section-config-runner.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
---
- include: line-config-runner.yml
vars:
line_name_prefix: "{{ sect_name_prefix }} line:[{{ (line_index|int) + 1 }}/{{ gitlab_runner.extra_configs[section]|list|length }}]: "
loop: "{{ gitlab_runner.extra_configs[section] | list }}"
loop_control:
loop_var: line
index_var: line_index
2 changes: 1 addition & 1 deletion tasks/systemd-reload.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
when: gitlab_runner_timeout_stop_seconds > 0
register: gitlab_runner_kill_timeout

- name: Force systemd to reread configs
- name: Force systemd to reread configs # noqa 503
become: yes
systemd:
daemon_reload: yes
Expand Down
Loading

0 comments on commit c8cfe5f

Please sign in to comment.