-
Notifications
You must be signed in to change notification settings - Fork 301
Fix for #420 (Conditionals must have a boolean result.) and basic tests for #425 #426
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,3 +2,4 @@ ansible.cfg | |
| .idea | ||
| .vscode | ||
| *.pyc | ||
| /.venv | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| --- | ||
| - name: Converge (apply role with selected vars) | ||
| hosts: runner | ||
| become: true | ||
|
|
||
| vars_files: | ||
| - vars/common.yml | ||
|
|
||
| pre_tasks: | ||
| - name: Load extra vars | ||
| ansible.builtin.include_vars: "{{ lookup('env', 'TEST_VARS_FILE') }}" | ||
| when: lookup('env', 'TEST_VARS_FILE') is defined | ||
|
|
||
| roles: | ||
| - role: riemers.gitlab_runner |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| concurrent = 8 | ||
| check_interval = 0 | ||
|
|
||
| [[runners]] | ||
| name = "Example Docker GitLab Runner" | ||
| limit = 0 | ||
| output_limit = 4096 | ||
| url = "http://mock:8000" | ||
| environment = [] | ||
| id = 0 | ||
| token_expires_at = 0001-01-01T00:00:00Z | ||
| executor = "docker" | ||
| [runners.docker] | ||
| image = "" | ||
| disable_cache = false | ||
| volumes = ["/cache"] | ||
| pull_policy = "if-not-present" | ||
| shm_size = 0 | ||
| [runners.feature_flags] | ||
| FF_TIMESTAMPS = true | ||
| [runners.cache] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| concurrent = 8 | ||
| check_interval = 0 | ||
|
|
||
| [[runners]] | ||
| name = "Example Docker GitLab Runner" | ||
| limit = 0 | ||
| url = "http://mock:8000" | ||
| environment = [] | ||
| output_limit = 32768 | ||
| id = 0 | ||
| token_expires_at = 0001-01-01T00:00:00Z | ||
| executor = "docker" | ||
| [runners.cache] | ||
| [runners.docker] | ||
| image = "alpine" | ||
| privileged = true | ||
| shm_size = 0 | ||
| disable_cache = false | ||
| pull_policy = "always" | ||
| volumes = ["/cache"] | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| flask |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| --- | ||
| dependency: | ||
| name: galaxy | ||
| options: | ||
| ignore-errors: true | ||
|
|
||
| driver: | ||
| name: docker | ||
| docker_networks: | ||
| - name: testnet | ||
| ipam_config: | ||
| - subnet: "172.28.0.0/16" | ||
| dns: | ||
| - 127.0.0.11 | ||
|
|
||
| platforms: | ||
| - name: mock | ||
| image: python:3.11-slim | ||
| pre_build_image: true | ||
| networks: | ||
| - name: testnet | ||
| command: > | ||
| bash -lc "pip install -r /srv/mock/requirements.txt && python /srv/mock/server.py 8000" | ||
| volumes: | ||
| - "${MOLECULE_SCENARIO_DIRECTORY}/mock:/srv/mock:ro" | ||
| published_ports: | ||
| - "8000:8000" | ||
|
|
||
| - name: runner | ||
| image: geerlingguy/docker-ubuntu2204-ansible | ||
| pre_build_image: true | ||
| networks: | ||
| - name: testnet | ||
| privileged: true | ||
| cgroupns_mode: host | ||
| volumes: | ||
| - /sys/fs/cgroup:/sys/fs/cgroup:rw | ||
| tmpfs: | ||
| - /run | ||
| - /run/lock | ||
| command: /sbin/init | ||
|
|
||
| provisioner: | ||
| name: ansible | ||
| playbooks: | ||
| converge: ${MOLECULE_PLAYBOOK:-converge.yml} | ||
| env: | ||
| TEST_VARS_FILE: "${TEST_VARS_FILE}" | ||
| EXPECTED_TOML: "${EXPECTED_TOML}" | ||
| inventory: | ||
| hosts: | ||
| all: | ||
| hosts: | ||
| mock: | ||
| runner: | ||
|
|
||
| verifier: | ||
| name: testinfra | ||
| options: | ||
| v: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| import os | ||
| import pytest | ||
| import tomllib | ||
| import testinfra.utils.ansible_runner | ||
|
|
||
| EXPECTED_ENV = "EXPECTED_TOML" | ||
| CONFIG_PATH = "/etc/gitlab-runner/config.toml" | ||
| IGNORED_CONFIG_FIELDS = ("token_obtained_at", "token") | ||
|
|
||
| testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner( | ||
| os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('runner') | ||
|
|
||
|
|
||
| def _load_toml_string(content: str): | ||
| return tomllib.loads(content) | ||
|
|
||
| def _load_toml_file(path: str): | ||
| with open(path, "rb") as f: | ||
| return tomllib.loads(f.read().decode("utf-8")) | ||
|
|
||
| def _normalize(cfg: dict): | ||
| cfg = dict(cfg) # płytka kopia | ||
| if "runners" in cfg and isinstance(cfg["runners"], list): | ||
| cleaned = [] | ||
| for r in cfg["runners"]: | ||
| r = dict(r) | ||
| for k in IGNORED_CONFIG_FIELDS: | ||
| r.pop(k, None) | ||
| cleaned.append(r) | ||
| cfg["runners"] = cleaned | ||
| return cfg | ||
|
|
||
| def test_config_matches_expected(host): | ||
| expected_path = os.environ.get(EXPECTED_ENV) | ||
| assert expected_path, f"{EXPECTED_ENV} variable not set" | ||
|
|
||
| f = host.file(CONFIG_PATH) | ||
| assert f.exists, f"{CONFIG_PATH} does not exist on host" | ||
| assert f.is_file, f"{CONFIG_PATH} is not a file" | ||
|
|
||
| got = _normalize(_load_toml_string(f.content_string)) | ||
| expected = _normalize(_load_toml_file(expected_path)) | ||
|
|
||
| assert got == expected, ( | ||
| "config.toml is different than expected\n" | ||
| f"Expected: {expected_path}" | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| gitlab_runner_coordinator_url: http://mock:8000 | ||
| gitlab_runner_no_log_secrets: true | ||
| gitlab_runner_config_update_mode: 'by_template' | ||
| gitlab_runner_registration_token_type: "authentication-token" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| gitlab_runner_runners: | ||
| - name: 'Example Docker GitLab Runner' | ||
| token: ABCD | ||
| executor: docker | ||
| docker_pull_policy: if-not-present | ||
| privileged: false | ||
| docker_disable_cache: false | ||
| docker_shm_size: 0 | ||
| tags: | ||
| - docker | ||
| docker_volumes: | ||
| - /cache | ||
| feature_flags: | ||
| FF_TIMESTAMPS: true |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| gitlab_runner_runners: | ||
| - name: 'Example Docker GitLab Runner' | ||
| token: ABCD | ||
| executor: docker | ||
| docker_pull_policy: always | ||
| docker_image: "alpine" | ||
| docker_privileged: true | ||
| docker_disable_cache: false | ||
| docker_shm_size: 0 | ||
| output_limit: 32768 | ||
| tags: | ||
| - docker | ||
| - privileged | ||
| docker_volumes: | ||
| - /cache |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pytest] | ||
| addopts = -vv --maxfail=1 --tb=short |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| ansible-core | ||
| molecule | ||
| molecule-plugins[docker] | ||
| pytest | ||
| testinfra |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #!/usr/bin/env bash | ||
| set -euox pipefail | ||
|
|
||
| molecule create | ||
|
|
||
|
|
||
| TEST_VARS_FILE=vars/initial.yml molecule converge | ||
| EXPECTED_TOML=expected/initial.toml molecule verify | ||
|
|
||
| TEST_VARS_FILE=vars/updated.yml molecule converge | ||
| EXPECTED_TOML=expected/updated.toml molecule verify | ||
|
|
||
| molecule destroy |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@riemers Changes in this file always ring alarm bells. Do you think this is again a problem with ansible galaxy? I mean the change should be done as the linter complained...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was needed for the molecule to use the role in the converge.yml playbook. It complained that the name wasn't set, as I remember.
I'm sorry, I missed that I used an "underscore" instead of a "dash" in the role name 🙈 I can revert it, remove the role_name check from the lint, and, as a role to test, use
"{{ playbook_dir }}/../..". What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import by path works in converge.yml, but molecule still doesn't like the role name. I'm not sure how to fix it :(