mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 03:38:23 +00:00
stack_host_copy is the copy: analogue of stack_host_template: it folds the IS_STACK_HOST gate into the module so callers do not silently fail on hosts whose destination tree is owned only by the stack host. In swarm an app's compose / build-context directory (/opt/compose/<app>) exists only on the manager, so a bare copy: into directories.instance also ran on workers and aborted the play with 'Destination directory does not exist'. Migrate the six compose-dir copy tasks (baserow, jenkins, bookwyrm, postmarks, yourls, openldap) to stack_host_copy and drop the now-redundant when: IS_STACK_HOST. A new drift-guard lint test (test_stack_host_copy_migration) flags any future bare copy: into the compose dir, and a unit test covers the wrapper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.1 KiB
Python
Executable File
31 lines
1.1 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
from __future__ import annotations
|
|
|
|
from typing import Any
|
|
|
|
from ansible.module_utils.parsing.convert_bool import boolean as _to_bool
|
|
from ansible.plugins.action.copy import ActionModule as CopyActionModule
|
|
from ansible.template import trust_as_template
|
|
|
|
# trust_as_template: Ansible 2.19+ refuses to render Python-constructed strings without the TrustedAsTemplate tag.
|
|
_IS_STACK_HOST_EXPR = trust_as_template("{{ IS_STACK_HOST | bool }}")
|
|
|
|
|
|
class ActionModule(CopyActionModule):
|
|
def run(
|
|
self, tmp: Any = None, task_vars: dict[str, Any] | None = None
|
|
) -> dict[str, Any]:
|
|
if task_vars is None:
|
|
task_vars = {}
|
|
|
|
self._templar.available_variables = task_vars
|
|
if not _to_bool(self._templar.template(_IS_STACK_HOST_EXPR)):
|
|
return {
|
|
"changed": False,
|
|
"skipped": True,
|
|
"skip_reason": "IS_STACK_HOST is false; this host does not own the destination",
|
|
}
|
|
|
|
self._task.args.setdefault("mode", "0644")
|
|
return super().run(tmp=tmp, task_vars=task_vars)
|