Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linting issues #312

Closed
wants to merge 16 commits into from
4 changes: 4 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
profile: production
warn_list:
- role-name # until role name is fixed on galaxy https://github.com/riemers/ansible-gitlab-runner/pull/312
2 changes: 0 additions & 2 deletions .github/workflows/ansible.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ on:
branches:
- master
workflow_dispatch:


jobs:
ansible-lint:
runs-on: ubuntu-latest
Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ jobs:
steps:
- uses: actions/stale@v8
with:
stale-issue-message: Seems this message did not get a lot of love. This does not mean it was not seen but time wise might not have made it to proper attention.
stale-issue-message: Seems this message did not get a lot of love.
This does not mean it was not seen but time wise might not have made it to proper attention.
This is just the clean up action ;)
stale-pr-message: Although PRs are appreciated, if it sits for too long nothing happens. Can always update and do again :) This is just the automation talking
stale-pr-message: Although PRs are appreciated, if it sits for too long nothing happens. Can always update and do again :)
This is just the automation talking
days-before-issue-stale: 30
days-before-pr-stale: 45
days-before-issue-close: 5
Expand Down
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
#- printf '[defaults]\nroles_path=../' > ansible.cfg
# - printf '[defaults]\nroles_path=../' > ansible.cfg
- "{ echo '[defaults]'; echo 'roles_path = ../'; } > ansible.cfg"
script:
# Basic role syntax check
Expand All @@ -30,7 +30,7 @@ jobs:
- os: osx
osx_image: xcode10.3
# See https://github.com/travis-ci/travis-ci/issues/2312#issuecomment-422830059
#language: python
# language: python
language: generic
install:
# Install ansible
Expand Down Expand Up @@ -59,7 +59,7 @@ jobs:
- cd ../../
- wsl ansible-playbook test.yml -i inventory --syntax-check
# Running tests
- wsl ansible-playbook test.yml -i inventory --extra-vars 'ansible_user=ansible ansible_password=Ans1ble_User! ansible_connection=winrm ansible_winrm_server_cert_validation=ignore
ansible_ssh_port=5986'
- wsl ansible-playbook test.yml -i inventory --extra-vars 'ansible_user=ansible ansible_password=Ans1ble_User!
ansible_connection=winrm ansible_winrm_server_cert_validation=ignore ansible_ssh_port=5986'
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/
2 changes: 1 addition & 1 deletion defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ gitlab_runner_timeout_stop_seconds: 7200
# gitlab_runner_log_format: runner

# defines value for log_level
# Defines the log level. Options are debug, info, warn, error, fatal, and panic.
# Defines the log level. Options are debug, info, warn, error, fatal, and panic.
# This setting has lower priority than the level set by the command-line arguments --debug, -l, or --log-level.
# gitlab_runner_log_level: "warning"

Expand Down
23 changes: 15 additions & 8 deletions handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
---
# non macOS
- name: restart_gitlab_runner
service: name=gitlab-runner state={{ gitlab_runner_restart_state }}
- name: Restart_gitlab_runner
ansible.builtin.service:
name: gitlab-runner
state: "{{ gitlab_runner_restart_state }}"
listen: restart_gitlab_runner
become: true
when: ansible_os_family != 'Darwin' and ansible_os_family != 'Windows' and not gitlab_runner_container_install

# macOS
- name: restart_gitlab_runner_macos
command: "{{ gitlab_runner_executable }} restart"
- name: Restart_gitlab_runner_macos
ansible.builtin.command: "{{ gitlab_runner_executable }} restart"
listen: restart_gitlab_runner_macos
become: "{{ gitlab_runner_system_mode }}"
changed_when: true
Copy link
Collaborator

@guenhter guenhter Apr 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I this necessary? Doesn't the command module produces a "changed" anyway?

when: ansible_os_family == 'Darwin' and gitlab_runner_macos_start_runner

- name: restart_gitlab_runner_windows
win_command: "{{ gitlab_runner_executable }} restart"
- name: Restart_gitlab_runner_windows
ansible.windows.win_command: "{{ gitlab_runner_executable }} restart"
args:
chdir: "{{ gitlab_runner_config_file_location }}"
listen: restart_gitlab_runner_windows
when: ansible_os_family == 'Windows' and gitlab_runner_windows_start_runner

# Container
- name: restart_gitlab_runner_container
docker_container:
- name: Restart_gitlab_runner_container
community.docker.docker_container:
name: "{{ gitlab_runner_container_name }}"
restart: true
listen: restart_gitlab_runner_container
when: gitlab_runner_container_install
4 changes: 1 addition & 3 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ galaxy_info:
namespace: riemers
description: GitLab Runner
license: MIT
min_ansible_version: 2.7
min_ansible_version: "2.7"
platforms:
- name: EL
versions:
Expand All @@ -25,5 +25,3 @@ galaxy_info:
- gitlab
- runner
- ci

dependencies: []
4 changes: 4 additions & 0 deletions requirements.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should close #342. the linting would already "fix" it. but not with optional dependencies.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
collections:
- name: ansible.windows
- name: community.docker
18 changes: 10 additions & 8 deletions tasks/config-runner-container.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
---
- name: "{{ conf_name_prefix }} Create temporary file"
tempfile:
- name: "Create temporary file {{ conf_name_prefix }}"
ansible.builtin.tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
prefix: gitlab-runner.{{ runner_config_index }}.
register: temp_runner_config
check_mode: false
changed_when: false

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

- include_tasks: update-config-runner.yml
- name: Update config
ansible.builtin.include_tasks: update-config-runner.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
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 @@ -26,8 +28,8 @@
index_var: gitlab_runner_index
loop_var: gitlab_runner

- name: "{{ conf_name_prefix }} Remove runner config"
file:
- name: "Remove runner config {{ conf_name_prefix }}"
ansible.builtin.file:
path: "{{ temp_runner_config.path }}"
state: absent
when:
Expand Down
17 changes: 9 additions & 8 deletions tasks/config-runner-windows.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
---
- name: (Windows) {{ conf_name_prefix }} Create temporary file
win_tempfile:
- name: "(Windows) Create temporary file {{ conf_name_prefix }}"
ansible.windows.win_tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
prefix: gitlab-runner.{{ runner_config_index }}.
register: temp_runner_config
check_mode: false
changed_when: false

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

- include_tasks: update-config-runner-windows.yml
- name: Update config
ansible.builtin.include_tasks: update-config-runner-windows.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
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 @@ -26,8 +27,8 @@
index_var: gitlab_runner_index
loop_var: gitlab_runner

- name: (Windows) {{ conf_name_prefix }} Remove runner config
win_file:
- name: "(Windows) Remove runner config {{ conf_name_prefix }}"
ansible.windows.win_file:
path: "{{ temp_runner_config.path }}"
state: absent
when:
Expand Down
18 changes: 10 additions & 8 deletions tasks/config-runner.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
---
- name: "{{ conf_name_prefix }} Create temporary file"
tempfile:
- name: "Create temporary file {{ conf_name_prefix }}"
ansible.builtin.tempfile:
state: file
path: "{{ temp_runner_config_dir.path }}"
prefix: gitlab-runner.{{ runner_config_index }}.
register: temp_runner_config
check_mode: false
changed_when: false

- name: "{{ conf_name_prefix }} Isolate runner configuration"
copy:
- name: "Isolate runner configuration {{ conf_name_prefix }}"
ansible.builtin.copy:
dest: "{{ temp_runner_config.path }}"
content: "{{ runner_config }}"
mode: "0644"
check_mode: false
changed_when: false
no_log: "{{ gitlab_runner_no_log_secrets | default(omit) }}"

- include_tasks: update-config-runner.yml
- name: Update config
ansible.builtin.include_tasks: update-config-runner.yml
vars:
runn_name_prefix: "{{ conf_name_prefix }} runner[{{ (gitlab_runner_index|int) + 1 }}/{{ gitlab_runner_runners|length }}]:"
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 @@ -28,8 +30,8 @@
loop_var: gitlab_runner
no_log: "{{ gitlab_runner_no_log_secrets | default(omit) }}"

- name: "{{ conf_name_prefix }} Remove runner config"
file:
- name: "Remove runner config {{ conf_name_prefix }}"
ansible.builtin.file:
path: "{{ temp_runner_config.path }}"
state: absent
when:
Expand Down
12 changes: 6 additions & 6 deletions tasks/config-runners-container.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
- name: Get existing config.toml
slurp:
ansible.builtin.slurp:
src: "{{ gitlab_runner_config_file }}"
register: runner_config_file

- name: Get pre-existing runner configs
set_fact:
ansible.builtin.set_fact:
runner_configs: "{{ (runner_config_file['content'] | b64decode).split('[[runners]]\n') }}"

- name: Create temporary directory
tempfile:
ansible.builtin.tempfile:
state: directory
suffix: gitlab-runner-config
register: temp_runner_config_dir
Expand All @@ -18,15 +18,15 @@

- 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
conf_name_prefix: "conf[{{ (runner_config_index | int) + 1 }}/{{ runner_configs | length }}]:"
ansible.builtin.include_tasks: config-runner-container.yml
loop: "{{ runner_configs }}"
loop_control:
index_var: runner_config_index
loop_var: runner_config

- name: Assemble new config.toml
assemble:
ansible.builtin.assemble:
src: "{{ temp_runner_config_dir.path }}"
dest: "{{ gitlab_runner_config_file }}"
delimiter: "[[runners]]\\n"
Expand Down
25 changes: 12 additions & 13 deletions tasks/config-runners-windows.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
---
- name: (Windows) Get existing config.toml
slurp:
ansible.builtin.slurp:
src: "{{ gitlab_runner_config_file }}"
register: runner_config_file

- name: (Windows) Get pre-existing global config
set_fact:
ansible.builtin.set_fact:
runner_global_config: "{{ (runner_config_file['content'] | b64decode).split('[[runners]]')[0] }}"

- name: (Windows) Get pre-existing runner configs
set_fact:
ansible.builtin.set_fact:
runner_configs: "{{ (runner_config_file['content'] | b64decode).split('[[runners]]')[1:] }}"

- name: (Windows) Create temporary directory
win_tempfile:
ansible.windows.win_tempfile:
state: directory
suffix: gitlab-runner-config
register: temp_runner_config_dir
Expand All @@ -22,8 +22,8 @@

- 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
conf_name_prefix: "conf[{{ (runner_config_index | int) + 1 }}/{{ runner_configs | length }}]:"
ansible.builtin.include_tasks: config-runner-windows.yml
loop: "{{ runner_configs }}"
loop_control:
index_var: runner_config_index
Expand All @@ -33,32 +33,31 @@
when: not ansible_check_mode
block:
- name: (Windows) Create temporary file config.toml
win_tempfile:
ansible.windows.win_tempfile:
state: file
suffix: temp
register: config_toml_temp

- name: (Windows) Write global config to file
win_lineinfile:
community.windows.win_lineinfile:
insertbefore: BOF
path: "{{ config_toml_temp.path }}"
line: "{{ runner_global_config }}"

- name: (Windows) Create temporary file runners-config.toml
win_tempfile:
ansible.windows.win_tempfile:
state: file
suffix: temp
register: runners_config_toml_temp

- name: (Windows) Assemble runners files in config dir
win_shell: dir -rec | gc | out-file "{{ runners_config_toml_temp.path }}"
ansible.windows.win_shell: dir -rec | gc | out-file "{{ runners_config_toml_temp.path }}"
args:
chdir: "{{ temp_runner_config_dir.path }}"

- name: (Windows) Assemble new config.toml
win_shell: gc "{{ config_toml_temp.path }}","{{ runners_config_toml_temp.path }}" | Set-Content "{{ gitlab_runner_config_file }}"

ansible.windows.win_shell: gc "{{ config_toml_temp.path }}","{{ runners_config_toml_temp.path }}" | Set-Content "{{ gitlab_runner_config_file }}"
- name: (Windows) Verify config
win_command: "{{ gitlab_runner_executable }} verify"
ansible.windows.win_command: "{{ gitlab_runner_executable }} verify"
args:
chdir: "{{ gitlab_runner_config_file_location }}"
Loading
Loading