mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
New 'image' lookup is the SPOT for resolving <registry>/<image>:<version> (swarm registry prefix in swarm mode, bare in compose; custom= accepts a string base for a second distinct custom image inside one app). container_image becomes a thin wrapper that forwards terms+kwargs and adds the compose image: "<ref>" line, so all existing template call sites keep their output byte-identical. The lookup-usage integration test now counts lookup_loader.get() delegation as production usage. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
"""Lookup `container_image`: compose ``image: "<ref>"`` line for a
|
|
container service.
|
|
|
|
Thin wrapper around the `image` lookup (the SPOT for resolving the
|
|
``<registry>/<image>:<version>`` reference). ``container_image`` only adds
|
|
the ``image: "..."`` compose-line wrapping so templates can drop it in as
|
|
a standalone statement:
|
|
|
|
# roles/web-app-X/templates/compose.yml.j2
|
|
{{ lookup('container_image', application_id, 'x') }}
|
|
|
|
# Locally-built image (no registry upstream).
|
|
{{ lookup('container_image', application_id, 'x', custom=True) }}
|
|
|
|
All resolution kwargs (``image=``, ``version=``, ``custom=``, ``tag_only=``)
|
|
are forwarded to `image`. For a bare reference (no wrapping), call the
|
|
`image` lookup directly.
|
|
|
|
Both terms (application_id, service_key) are required; they are validated
|
|
by `image`.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.plugins.loader import lookup_loader
|
|
from ansible.plugins.lookup import LookupBase
|
|
|
|
|
|
class LookupModule(LookupBase):
|
|
def run(
|
|
self,
|
|
terms: list[Any] | None,
|
|
variables: dict[str, Any] | None = None,
|
|
**kwargs: Any,
|
|
) -> list[str]:
|
|
ref = lookup_loader.get(
|
|
"image", loader=self._loader, templar=getattr(self, "_templar", None)
|
|
).run(terms, variables=variables, **kwargs)[0]
|
|
return [f'image: "{ref}"']
|