-
-
Notifications
You must be signed in to change notification settings - Fork 235
feat: add ansible task testing infrastructure based on Docker and pytest #1882
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
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| --- | ||
| profile: production | ||
|
|
||
| # exclude_paths included in this file are parsed relative to this file's location | ||
| # and not relative to the CWD of execution. CLI arguments passed to the --exclude | ||
| # option are parsed relative to the CWD of execution. | ||
| exclude_paths: | ||
| - .cache/ # implicit unless exclude_paths is defined in config | ||
| - .github/ | ||
| - ansible/files/ | ||
| - ansible/manifest-playbook.yml | ||
| - ansible/playbook.yml | ||
| - ansible/tasks/ | ||
| - audit-specs/ | ||
| - nix/mkdocs.yml | ||
|
|
||
| use_default_rules: true | ||
| enable_list: | ||
| - args | ||
| - empty-string-compare | ||
| - no-log-password | ||
| - no-same-owner | ||
| warn_list: | ||
| - experimental | ||
| skip_list: | ||
| - name[casing] | ||
| - name[prefix] | ||
| - yaml[line-length] | ||
| - var-naming[no-role-prefix] | ||
|
|
||
| # Offline mode disables installation of requirements.yml | ||
| offline: false | ||
|
|
||
| # Make the output more readable | ||
| parseable: true | ||
|
|
||
| # Define required Ansible's variables to satisfy syntax check | ||
| # extra_vars: | ||
|
|
||
| # List of additional kind:pattern to be added at the top of the default | ||
| # match list, first match determines the file kind. | ||
| kinds: | ||
| - tasks: "ansible/tasks/*.yml" | ||
| - vars: "ansible/vars.yml" | ||
This file was deleted.
jfroche marked this conversation as resolved.
Show resolved
Hide resolved
|
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| name: Ansible Test Image CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - develop | ||
| pull_request: | ||
| workflow_dispatch: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| build-and-push: | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/develop' | ||
| strategy: | ||
| matrix: | ||
| arch: [amd64, arm64] | ||
| runs-on: ${{ matrix.arch == 'amd64' && 'blacksmith-16vcpu-ubuntu-2404' || 'blacksmith-16vcpu-ubuntu-2404-arm' }} | ||
| steps: | ||
| - name: Checkout Repo | ||
| uses: supabase/postgres/.github/actions/shared-checkout@HEAD | ||
|
|
||
| - name: Install Nix | ||
| uses: ./.github/actions/nix-install-ephemeral | ||
| with: | ||
| push-to-cache: true | ||
| env: | ||
| DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} | ||
| NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Build Docker image with Nix | ||
| run: | | ||
| echo "Building ansible-test Docker image for ${{ matrix.arch }}..." | ||
| IMAGE_PATH=$(nix build .#docker-ansible-test --print-out-paths) | ||
| echo "IMAGE_PATH=$IMAGE_PATH" >> "$GITHUB_ENV" | ||
|
|
||
| - name: Load and push Docker image | ||
| run: | | ||
| echo "Loading Docker image..." | ||
| docker load < "$IMAGE_PATH" | ||
| docker tag supabase/ansible-test:latest supabase/ansible-test:latest-${{ matrix.arch }} | ||
| docker push supabase/ansible-test:latest-${{ matrix.arch }} | ||
|
|
||
| create-manifest: | ||
| if: github.event_name == 'push' && github.ref == 'refs/heads/develop' | ||
| needs: build-and-push | ||
| runs-on: 'blacksmith-4vcpu-ubuntu-2404' | ||
| steps: | ||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Create and push multi-arch manifest | ||
| run: | | ||
| docker manifest create supabase/ansible-test:latest \ | ||
| supabase/ansible-test:latest-amd64 \ | ||
| supabase/ansible-test:latest-arm64 | ||
| docker manifest push supabase/ansible-test:latest | ||
|
|
||
| run-ansible-tests: | ||
| if: ${{ !failure() && !cancelled() }} | ||
| needs: create-manifest | ||
| runs-on: 'blacksmith-16vcpu-ubuntu-2404' | ||
jfroche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| steps: | ||
| - name: Checkout Repo | ||
| uses: supabase/postgres/.github/actions/shared-checkout@HEAD | ||
|
|
||
| - name: Install Nix | ||
| uses: ./.github/actions/nix-install-ephemeral | ||
| with: | ||
| push-to-cache: true | ||
| env: | ||
| DEV_AWS_ROLE: ${{ secrets.DEV_AWS_ROLE }} | ||
| NIX_SIGN_SECRET_KEY: ${{ secrets.NIX_SIGN_SECRET_KEY }} | ||
|
|
||
| - name: Login to Docker Hub | ||
| uses: docker/login-action@v3 | ||
| with: | ||
| username: ${{ secrets.DOCKER_USERNAME }} | ||
| password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
|
||
| - name: Run Ansible tests | ||
| env: | ||
| PY_COLORS: '1' | ||
| ANSIBLE_FORCE_COLOR: '1' | ||
| run: | | ||
| docker pull supabase/ansible-test:latest & | ||
| nix run .#ansible-test | ||
jfroche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| ../files |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,84 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import pytest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import subprocess | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import testinfra | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| from rich.console import Console | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console = Console() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def pytest_addoption(parser): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.addoption( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--flake-dir", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action="store", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Directory containing the current flake", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| parser.addoption( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--docker-image", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| action="store", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| help="Docker image and tag to use for testing", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jfroche marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @pytest.fixture(scope="module") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def host(request): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| flake_dir = request.config.getoption("--flake-dir") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not flake_dir: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pytest.fail("--flake-dir option is required") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker_image = request.config.getoption("--docker-image") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if not docker_image: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pytest.fail("--docker-image option is required") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker_id = ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.check_output( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "docker", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "run", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--privileged", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--cap-add", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "SYS_ADMIN", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--security-opt", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "seccomp=unconfined", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--cgroup-parent=docker.slice", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--cgroupns", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "private", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-v", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"{flake_dir}:/flake", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-d", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| docker_image, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .decode() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .strip() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| yield testinfra.get_host("docker://" + docker_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| subprocess.check_call(["docker", "rm", "-f", docker_id], stdout=subprocess.DEVNULL) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+23
to
+54
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: rg -n -- "--flake-dir" -A 2 -B 2Repository: supabase/postgres Length of output: 230 🏁 Script executed: cat -n ansible/tests/conftest.py | head -60Repository: supabase/postgres Length of output: 2045 🏁 Script executed: git ls-files | grep -E "(conftest|pytest)" | head -20Repository: supabase/postgres Length of output: 86 🏁 Script executed: rg -n "flake-dir"Repository: supabase/postgres Length of output: 450 🏁 Script executed: rg -n "flake.dir\|flake_dir" ansible/tests/Repository: supabase/postgres Length of output: 43 🏁 Script executed: find . -type f -name "*.sh" -o -name "*.yml" -o -name "*.yaml" | head -20Repository: supabase/postgres Length of output: 807 🏁 Script executed: cat -n nix/packages/ansible-test.nixRepository: supabase/postgres Length of output: 754 🏁 Script executed: cat -n .github/workflows/ansible-tests.ymlRepository: supabase/postgres Length of output: 3842 🏁 Script executed: rg -n "FLAKE_DIR" nix/Repository: supabase/postgres Length of output: 285 🏁 Script executed: rg -n "from pathlib\|import pathlib" ansible/Repository: supabase/postgres Length of output: 43 🏁 Script executed: rg -n "Path\|pathlib" ansible/tests/Repository: supabase/postgres Length of output: 43 🏁 Script executed: rg -n "is_dir\|exists()" ansible/ | head -20Repository: supabase/postgres Length of output: 43 🏁 Script executed: cat -n ansible/tests/conftest.py | sed -n '54,80p'Repository: supabase/postgres Length of output: 1059 🏁 Script executed: rg -n "docker.*-v" ansible/Repository: supabase/postgres Length of output: 43 🏁 Script executed: python3 << 'EOF'
import pathlib
# Check if pathlib is available and works as expected
p = pathlib.Path("/tmp").expanduser().resolve()
print(f"Path exists: {p.is_dir()}")
print(f"Path type: {type(p)}")
EOFRepository: supabase/postgres Length of output: 117 🏁 Script executed: # Check if there are any other fixtures or functions that validate paths
rg -n "pytest.fail\|is_dir\|exists" ansible/tests/conftest.pyRepository: supabase/postgres Length of output: 43 🏁 Script executed: # Verify the exact Docker behavior with non-existent paths in this context
# by checking if there's any error handling for Docker mount issues
rg -n "docker.*run\|subprocess" ansible/tests/conftest.py -A 5Repository: supabase/postgres Length of output: 43 🏁 Script executed: # Check what happens when docker run is called with non-existent mount path
# by looking at Docker documentation or testing behavior
python3 << 'EOF'
import subprocess
import tempfile
# Simulate what Docker does with non-existent paths
# Docker typically just creates an empty directory if the source doesn't exist
# Let's verify the concern: checking if Docker silently creates empty dirs
# by examining the current setup
print("Docker behavior with non-existent source paths:")
print("- Docker will mount a volume even if source doesn't exist (creates empty dir)")
print("- This would cause confusing errors later in the test execution")
print("- Early validation would catch this and fail explicitly")
EOFRepository: supabase/postgres Length of output: 306 🏁 Script executed: # Check if there are any CI logs or error handling that shows this is a real issue
rg -n "mount\|volume" ansible/Repository: supabase/postgres Length of output: 43 🏁 Script executed: # Verify the proposed fix doesn't break anything by checking all imports
head -10 ansible/tests/conftest.pyRepository: supabase/postgres Length of output: 217 Add validation that Docker will silently mount an empty directory if the source path doesn't exist, causing confusing test failures later. Validating early provides immediate, explicit feedback. Suggested implementation+from pathlib import Path flake_dir = request.config.getoption("--flake-dir")
if not flake_dir:
pytest.fail("--flake-dir option is required")
+ flake_dir_path = Path(flake_dir).expanduser().resolve()
+ if not flake_dir_path.is_dir():
+ pytest.fail(f"--flake-dir must be an existing directory: {flake_dir}")
docker_image = request.config.getoption("--docker-image")
if not docker_image:
pytest.fail("--docker-image option is required")
@@
- f"{flake_dir}:/flake",
+ f"{flake_dir_path}:/flake",📝 Committable suggestion
Suggested change
🧰 Tools🪛 Ruff (0.14.14)[error] 32-32: (S603) [error] 33-48: Starting a process with a partial executable path (S607) [error] 54-54: (S603) [error] 54-54: Starting a process with a partial executable path (S607) 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| @pytest.fixture(scope="module") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def run_ansible_playbook(host): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def _run_playbook(playbook_name, verbose=False): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "ANSIBLE_HOST_KEY_CHECKING=False", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "ansible-playbook", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--connection=local", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if verbose: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd.append("-vvv") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| cmd.extend( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "-i", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "localhost,", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "--extra-vars", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "@/flake/ansible/vars.yml", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"/flake/ansible/tests/{playbook_name}", | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| result = host.run(" ".join(cmd)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if result.failed: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(result.stdout) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| console.log(result.stderr) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| pytest.fail( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| f"Ansible playbook {playbook_name} failed with return code {result.rc}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return _run_playbook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| --- | ||
| - name: Setup Nginx Server | ||
| hosts: localhost | ||
| tasks: | ||
| - name: Install dependencies | ||
| ansible.builtin.apt: | ||
| pkg: | ||
| - build-essential | ||
| update_cache: true | ||
| - name: Setup Nginx using existing task file | ||
| ansible.builtin.import_tasks: ../tasks/setup-nginx.yml | ||
| - name: Start Nginx service | ||
| ansible.builtin.service: | ||
| name: nginx | ||
| state: started | ||
| enabled: true | ||
jfroche marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| import pytest | ||
|
|
||
|
|
||
| @pytest.fixture(scope="module", autouse=True) | ||
| def run_ansible(run_ansible_playbook): | ||
| run_ansible_playbook("nginx.yaml") | ||
|
|
||
|
|
||
| def test_nginx_service(host): | ||
| assert host.service("nginx.service").is_valid | ||
| assert host.service("nginx.service").is_running |
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.
🧩 Analysis chain
🏁 Script executed:
Repository: supabase/postgres
Length of output: 80
🏁 Script executed:
Repository: supabase/postgres
Length of output: 1467
🏁 Script executed:
Repository: supabase/postgres
Length of output: 1231
Remove the
ansible/tasks/exclusion to enable task linting.The configuration excludes
ansible/tasks/from linting while also defining akindspattern for task files in the same directory. This contradiction prevents ansible-lint from checking any task files. If this PR aims to validate tasks, remove theansible/tasks/line fromexclude_paths.Additionally, note that the
kindspatternansible/tasks/*.ymlonly matches top-level files and will miss nested tasks inansible/tasks/internal/(e.g.,admin-api.yml,install-salt.yml). Consider updating the pattern toansible/tasks/**/*.ymlif nested tasks should be linted.Suggested fix
exclude_paths: - .cache/ # implicit unless exclude_paths is defined in config - .github/ - ansible/files/ - ansible/manifest-playbook.yml - ansible/playbook.yml - - ansible/tasks/ - audit-specs/ - nix/mkdocs.ymlAnd optionally update the kinds pattern:
📝 Committable suggestion
🤖 Prompt for AI Agents