Refactor state structure and capture versions of packages
This commit is contained in:
parent
984b0fa81b
commit
043802e800
6 changed files with 294 additions and 42 deletions
|
|
@ -271,9 +271,7 @@ def _write_hostvars(site_root: str, fqdn: str, role: str, data: Dict[str, Any])
|
|||
|
||||
merged = _merge_mappings_overwrite(existing_map, data)
|
||||
|
||||
out = "# Generated by enroll (host-specific vars)\n---\n" + _yaml_dump_mapping(
|
||||
merged, sort_keys=True
|
||||
)
|
||||
out = "---\n" + _yaml_dump_mapping(merged, sort_keys=True)
|
||||
with open(path, "w", encoding="utf-8") as f:
|
||||
f.write(out)
|
||||
|
||||
|
|
@ -392,7 +390,7 @@ def _render_generic_files_tasks(
|
|||
# Using first_found makes roles work in both modes:
|
||||
# - site-mode: inventory/host_vars/<host>/<role>/.files/...
|
||||
# - non-site: roles/<role>/files/...
|
||||
return f"""# Generated by enroll
|
||||
return f"""
|
||||
|
||||
- name: Deploy any systemd unit files (templates)
|
||||
ansible.builtin.template:
|
||||
|
|
@ -477,7 +475,7 @@ def _render_install_packages_tasks(role: str, var_prefix: str) -> str:
|
|||
generic `package` module. This keeps generated roles usable on both
|
||||
Debian-like and RPM-like systems.
|
||||
"""
|
||||
return f"""# Generated by enroll
|
||||
return f"""
|
||||
|
||||
- name: Install packages for {role} (APT)
|
||||
ansible.builtin.apt:
|
||||
|
|
@ -672,14 +670,16 @@ def _manifest_from_bundle_dir(
|
|||
with open(state_path, "r", encoding="utf-8") as f:
|
||||
state = json.load(f)
|
||||
|
||||
services: List[Dict[str, Any]] = state.get("services", [])
|
||||
package_roles: List[Dict[str, Any]] = state.get("package_roles", [])
|
||||
users_snapshot: Dict[str, Any] = state.get("users", {})
|
||||
apt_config_snapshot: Dict[str, Any] = state.get("apt_config", {})
|
||||
dnf_config_snapshot: Dict[str, Any] = state.get("dnf_config", {})
|
||||
etc_custom_snapshot: Dict[str, Any] = state.get("etc_custom", {})
|
||||
usr_local_custom_snapshot: Dict[str, Any] = state.get("usr_local_custom", {})
|
||||
extra_paths_snapshot: Dict[str, Any] = state.get("extra_paths", {})
|
||||
roles: Dict[str, Any] = state.get("roles") or {}
|
||||
|
||||
services: List[Dict[str, Any]] = roles.get("services", [])
|
||||
package_roles: List[Dict[str, Any]] = roles.get("packages", [])
|
||||
users_snapshot: Dict[str, Any] = roles.get("users", {})
|
||||
apt_config_snapshot: Dict[str, Any] = roles.get("apt_config", {})
|
||||
dnf_config_snapshot: Dict[str, Any] = roles.get("dnf_config", {})
|
||||
etc_custom_snapshot: Dict[str, Any] = roles.get("etc_custom", {})
|
||||
usr_local_custom_snapshot: Dict[str, Any] = roles.get("usr_local_custom", {})
|
||||
extra_paths_snapshot: Dict[str, Any] = roles.get("extra_paths", {})
|
||||
|
||||
site_mode = fqdn is not None and fqdn != ""
|
||||
|
||||
|
|
@ -839,7 +839,6 @@ def _manifest_from_bundle_dir(
|
|||
|
||||
# tasks (data-driven)
|
||||
users_tasks = """---
|
||||
# Generated by enroll
|
||||
|
||||
- name: Ensure groups exist
|
||||
ansible.builtin.group:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue