|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +Guidelines for AI agents working on this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +This is an Ansible role (`netdata`) that deploys and configures the [Netdata](https://www.netdata.cloud/) monitoring agent on Linux systems. It supports Debian, Ubuntu, and openSUSE platforms. |
| 8 | + |
| 9 | +## Repository Structure |
| 10 | + |
| 11 | +This repository follows the standard Ansible role directory layout: |
| 12 | + |
| 13 | +``` |
| 14 | +netdata-ansible/ |
| 15 | + defaults/main.yml # Default variable values for the role |
| 16 | + handlers/main.yml # Handlers (restart Netdata, reload claiming state) |
| 17 | + meta/main.yml # Role metadata for Ansible Galaxy |
| 18 | + tasks/ |
| 19 | + main.yml # Top-level task dispatcher |
| 20 | + install-debian.yml # Debian/Ubuntu package installation |
| 21 | + install-opensuse.yml # openSUSE package installation |
| 22 | + configure-linux.yml # Configuration file management |
| 23 | + node_claim.yml # Netdata Cloud node claiming |
| 24 | + templates/ |
| 25 | + claim.conf.j2 # Claiming configuration template |
| 26 | + go.d/plugin.conf.j2 # Go collector plugin configuration template |
| 27 | + tests/ |
| 28 | + test.yml # CI integration test playbook |
| 29 | + netdata.conf.j2 # Test configuration template |
| 30 | + example.chart.j2 # Test chart template |
| 31 | + roles/netdata # Symlink to repository root (`../../`) so the test |
| 32 | + # playbook can reference the role by its name |
| 33 | + # (`role: netdata`) via Ansible's default |
| 34 | + # roles_path resolution. |
| 35 | + .github/ |
| 36 | + workflows/ |
| 37 | + linux-ci.yml # Integration tests (matrix strategy, 7 OS versions) |
| 38 | + linting.yml # Ansible Lint checks |
| 39 | + CODEOWNERS # Code ownership rules |
| 40 | + .gitignore # Git ignore rules (excludes .fastforward/) |
| 41 | + README.md # User-facing documentation |
| 42 | + AGENTS.md # This file |
| 43 | +``` |
| 44 | + |
| 45 | +## CI Workflows |
| 46 | + |
| 47 | +Two GitHub Actions workflows run on every push and pull request: |
| 48 | + |
| 49 | +### Integration Test (`linux-ci.yml`) |
| 50 | + |
| 51 | +Uses GitHub Actions matrix strategy to run `ansible-playbook tests/test.yml` across seven container environments, organized into two jobs by package manager: |
| 52 | + |
| 53 | +**`apt-test`** (Debian and Ubuntu, uses `apt-get`): |
| 54 | + |
| 55 | +| Container Image | |
| 56 | +|----------------| |
| 57 | +| `debian:bullseye` | |
| 58 | +| `debian:bookworm` | |
| 59 | +| `ubuntu:22.04` | |
| 60 | +| `ubuntu:24.04` | |
| 61 | + |
| 62 | +**`opensuse-test`** (openSUSE Leap and Tumbleweed, uses `zypper`): |
| 63 | + |
| 64 | +| Container Image | `community.general` Version | |
| 65 | +|----------------|----------------------------| |
| 66 | +| `opensuse/leap:15.6` | latest | |
| 67 | +| `opensuse/leap:16.0` | latest | |
| 68 | +| `opensuse/tumbleweed` | latest | |
| 69 | + |
| 70 | +Both jobs set `fail-fast: false` so all matrix entries run even if one fails. Each job installs Ansible inside the container, checks out the code, and runs the test playbook. The `opensuse-test` job additionally installs the `community.general` Ansible collection via `ansible-galaxy`, because the openSUSE Leap `ansible` package does not bundle it. This collection provides the `community.general.zypper` and `community.general.zypper_repository` modules that the role requires. |
| 71 | + |
| 72 | +The `opensuse-test` matrix uses `include` entries with a `community_general_version` variable to control the installed collection version per image. All current entries install the latest version. When adding new openSUSE matrix entries, check the Python version in the container. If the Python version is below 3.7, pin `community.general` to 3.8.8 (the last release supporting Python 3.6 and Ansible 2.9). |
| 73 | + |
| 74 | +### Linting (`linting.yml`) |
| 75 | + |
| 76 | +Runs `ansible-lint` via the `ansible/ansible-lint@main` action. The lint configuration excludes `tests/test.yml` and skips the `role-name` rule. |
| 77 | + |
| 78 | +### Actions Pinning Convention |
| 79 | + |
| 80 | +All GitHub Actions checkout steps use `actions/checkout@v6` (Node.js 24). Keep this version current to avoid Node.js deprecation warnings. |
| 81 | + |
| 82 | +## Key Files |
| 83 | + |
| 84 | +### `meta/main.yml` |
| 85 | + |
| 86 | +Ansible Galaxy role metadata. Valid top-level keys are `galaxy_info`, `dependencies`, and `allow_duplicates` only. Do NOT add a top-level `version` key; Ansible roles derive versions from Git tags, not from role metadata. |
| 87 | + |
| 88 | +The `galaxy_info.platforms` list declares supported platforms for Ansible Galaxy. Platform names and version strings must match the ansible-lint `schema[meta]` rule. When a specific OS minor version is not in the Galaxy schema's allowed enum, use `versions: [all]` instead of explicit version numbers. |
| 89 | + |
| 90 | +### `defaults/main.yml` |
| 91 | + |
| 92 | +All role variables with their defaults. See `README.md` for a complete variable reference table. |
| 93 | + |
| 94 | +### `tasks/main.yml` |
| 95 | + |
| 96 | +Entry point for role execution. Dispatches to platform-specific install tasks based on `ansible_facts.distribution`, then runs configuration and claiming tasks when enabled. |
| 97 | + |
| 98 | +### `tasks/install-debian.yml` |
| 99 | + |
| 100 | +Handles Debian and Ubuntu package installation. Uses the modern `signed-by` keyring approach for GPG key management: |
| 101 | + |
| 102 | +1. Installs `gnupg` (required for key dearmoring). |
| 103 | +2. Creates `/etc/apt/keyrings/` directory. |
| 104 | +3. Downloads the ASCII-armored GPG key to `/etc/apt/keyrings/netdata.asc`. |
| 105 | +4. Dearmors the key to binary format at `/etc/apt/keyrings/netdata.gpg`. |
| 106 | +5. References the binary keyring via `[signed-by=...]` in the apt source line. |
| 107 | + |
| 108 | +Do NOT use `ansible.builtin.apt_key` in this file. It wraps the deprecated `apt-key` utility, which fails on Debian 12+ and Ubuntu 22.04+ with subkey validation errors. |
| 109 | + |
| 110 | +### `tasks/install-opensuse.yml` |
| 111 | + |
| 112 | +Handles openSUSE Leap and Tumbleweed package installation. Installs `libnetfilter_acct1` from the standard Leap 15.x repositories (skipped on Leap 16.0+ and Tumbleweed where the package is unavailable), imports the Netdata GPG key, adds the Netdata package repository, and installs the `netdata` package (plus optional chart support). |
| 113 | + |
| 114 | +All zypper-related tasks use the `community.general` collection (`community.general.zypper` and `community.general.zypper_repository`). This collection must be available on the control node. |
| 115 | + |
| 116 | +The repository URL uses a computed version path segment: the literal string `tumbleweed` for Tumbleweed, or the zypper `$releasever` variable for Leap. Do not hardcode version-specific repository URLs. The `libnetfilter_acct1` package is available from the standard Leap 15.x Main Repository and does not require an external repository. It is not available on Leap 16.0+ or Tumbleweed; the install task skips it on those systems via a version comparison condition. |
| 117 | + |
| 118 | +## Conventions |
| 119 | + |
| 120 | +### YAML Style |
| 121 | + |
| 122 | +- Use `---` document start markers in Ansible YAML files. |
| 123 | +- Use fully qualified collection names for modules (e.g., `ansible.builtin.setup`, not `setup`). |
| 124 | +- Quote string values in variable definitions. |
| 125 | + |
| 126 | +### Task Naming |
| 127 | + |
| 128 | +- Every task must have a `name` field with a descriptive label. |
| 129 | +- Use the pattern: verb + object (e.g., "Install dependencies", "Configure Netdata"). |
| 130 | + |
| 131 | +### Testing |
| 132 | + |
| 133 | +- The integration test playbook is `tests/test.yml`. It runs the role against `localhost` with `netdata_manage_config: true` and `netdata_manage_charts: true`. |
| 134 | +- The playbook references the role by name (`role: netdata`). The role is resolved via the `tests/roles/netdata` symlink that points at the repository root (`../../`). This is the standard Ansible Galaxy convention for testing a role from within its own repository. Do NOT change the playbook to use a relative path like `role: ../netdata-ansible`; that path is brittle because Ansible resolves role paths relative to the playbook file, and the parent directory name depends on how the repo was checked out (in CI it is `ansible`, not `netdata-ansible`). |
| 135 | +- CI tests validate that the role installs successfully. They do not validate Netdata runtime behavior (the containers do not run systemd). |
| 136 | + |
| 137 | +### Variable Naming |
| 138 | + |
| 139 | +- All role variables are prefixed with `netdata_`. |
| 140 | +- Boolean variables use `true`/`false`, not `yes`/`no`. |
| 141 | + |
| 142 | +### Git Ignore Rules |
| 143 | + |
| 144 | +- The `.gitignore` file excludes `.fastforward/` (the runtime artifact directory used by multi-session AI workflows). |
| 145 | +- Do NOT commit files under `.fastforward/`. If a file gets tracked before its `.gitignore` entry exists, remove it from the index with `git rm --cached <path>`. Do NOT use `git rm` without `--cached`; that deletes the file from disk. |
| 146 | + |
| 147 | +### Commit Messages |
| 148 | + |
| 149 | +- Follow conventional commit format: `type: description`. |
| 150 | +- Common types: `fix`, `feat`, `docs`, `ci`, `refactor`. |
| 151 | +- Keep the subject line concise (under 72 characters). |
0 commit comments