Debian Codegraph @

context/code-structure.md

raw
1 # Core structure
2
3 - `lib/ansible/` - Main Ansible library code.
4 - `cli/` - Command-line interface implementations (ansible, ansible-playbook, etc.).
5 - `executor/` - Task execution engine and strategies (includes PowerShell support in `powershell/`).
6 - `inventory/` - Inventory management and parsing.
7 - `modules/` - Core modules (built-in automation modules).
8 - `module_utils/` - Shared utilities for modules (includes C# in `csharp/` and PowerShell in `powershell/`).
9 - `plugins/` - Plugin framework (filters, tests, lookups, etc.).
10 - `vars/` - Variable management.
11 - `config/` - Configuration handling.
12 - `collections/` - Ansible Collections framework.
13
14 ## Key components
15
16 - **CLI Layer**: Entry points in `lib/ansible/cli/` handle command parsing and dispatch.
17 - **Executor**: `lib/ansible/executor/` contains the core execution engine that runs tasks and plays.
18 - **Module System**: Modules in `lib/ansible/modules/` are the units of work; they're executed remotely.
19 - **Plugin Architecture**: `lib/ansible/plugins/` provides extensibility through filters, tests, lookups, etc.
20 - **Inventory**: `lib/ansible/inventory/` manages host and group definitions.
21 - **Collections**: Modern packaging format for distributing Ansible content.
22
23 ## Plugin development
24
25 - New plugins should go into collections, not ansible-core.
26 - ansible-core rarely accepts new plugins; core team makes these decisions.
27
28 ## Import restrictions
29
30 - `lib/ansible/modules/` can only import from `lib/ansible/module_utils/` (modules are packaged for remote execution).
31 - `lib/ansible/module_utils/` cannot import from outside itself.
32
33 ## Resource embedding
34
35 Modules that need to execute code on Python versions outside the normal module_utils range
36 can use `EmbedManager.embed()` from `ansible.module_utils.embed` to bundle standalone scripts into the AnsiballZ payload.
37 Embedded resources go in `lib/ansible/module_utils/_embed/`.
38
39 ## Testing infrastructure
40
41 - `test/units/` - Unit tests mirroring the lib structure.
42 - `test/integration/` - Integration tests organized by target (named after plugin/functionality being tested).
43 - Some targets have `context/controller` or `context/target` in their `aliases` file when not easily inferable.
44 - Only modules run on target hosts; all other plugins execute locally in the ansible process.
45 - `test/lib/` - Test utilities and frameworks.
46 - `ansible-test` - Unified testing tool for all test types.