Files
computer-playbook/lookup_plugins/container.py
T
kevinveenbirkenbach a55c99ef62 refactor(compose): replace docker lookup with container and unify compose paths
- Rename lookup plugin from `docker` to `container`
- Switch all lookups from `lookup('docker', ...)` to `lookup('container', ...)`
- Normalize compose file keys:
  - docker_compose → compose
  - docker_compose_override → compose_override
  - docker_compose_ca_override → compose_ca_override
- Centralize compose path resolution via docker_paths_utils
- Update compose_file_args to always derive paths from DIR_COMPOSITIONS
- Align all roles, templates, and vars with container/compose naming
- Update and rename unit tests accordingly

This prepares the codebase for engine-agnostic container backends
(e.g. Docker ↔ Podman) and removes legacy docker-specific assumptions.

https://chatgpt.com/share/6987a7cc-d374-800f-99ad-bb4c8f92c59e
2026-02-07 21:59:39 +01:00

54 lines
1.6 KiB
Python

from __future__ import annotations
from typing import Any, Dict, Optional
from ansible.errors import AnsibleError
from ansible.plugins.lookup import LookupBase
from module_utils.docker_paths_utils import get_docker_paths
def _as_str(v: Any) -> str:
return "" if v is None else str(v).strip()
def _deep_get(d: Dict[str, Any], path: str) -> Any:
cur: Any = d
for key in path.split("."):
if not isinstance(cur, dict) or key not in cur:
raise AnsibleError(f"lookup('container'): invalid path '{path}'")
cur = cur[key]
return cur
class LookupModule(LookupBase):
"""
lookup('container', application_id[, path])
path can be:
- 'directories' / 'files' (returns sub-dict)
- 'directories.instance' (returns leaf)
"""
def run(self, terms, variables: Optional[Dict[str, Any]] = None, **kwargs):
if not terms or len(terms) > 2:
raise AnsibleError("lookup('container', application_id[, path])")
application_id = _as_str(terms[0])
if not application_id:
raise AnsibleError("lookup('container'): application_id is empty")
base = _as_str((variables or {}).get("DIR_COMPOSITIONS"))
if not base:
raise AnsibleError("lookup('container'): DIR_COMPOSITIONS not set")
paths = get_docker_paths(application_id, base)
if len(terms) == 2:
path = _as_str(terms[1])
if not path:
raise AnsibleError("lookup('container'): path is empty")
return [_deep_get(paths, path)]
return [paths]