mirror of
https://github.com/mulgadc/spinifex.git
synced 2026-10-21 11:46:37 +00:00
e7bbc64a45
spx admin init now rejects --external-mode=nat and demands --external-pool when mode=pool. The ansible init role silently skipped pool flags when the range was unset, so installs fell over inside the spx validator. Make targets also swallowed `-e` (make's env-override flag), so operators could not override pool start/end without editing defaults.yml. - vars/defaults.yml: rename nat_gateway_ip → external_gateway_ip; add spinifex_external_no_external opt-out; document the spx flag contract. - roles/init/tasks/main.yml: drop NAT branch; assert pool range upfront with a fail_msg pointing at EXTRA_VARS / defaults.yml; emit gateway, prefix-len, gateway-ip only when explicitly set (let spx auto-detect); honour --no-external. - playbooks/dev-reset.yml: rename captured var; coerce legacy external_mode=nat to pool with a warn; tighten gateway regex with \b. - Makefile: ansible-dev-* targets now forward EXTRA_VARS="key=val ..." through --extra-vars so `make` callers can override without editing defaults.yml. - scripts/ansible/README.md: document pool requirement, both invocation styles (direct -e vs make EXTRA_VARS), NAT removal.
73 lines
3.5 KiB
YAML
73 lines
3.5 KiB
YAML
---
|
|
- name: Dev reset — capture settings, wipe, rebuild, reinstall, re-init, smoketest
|
|
hosts: localhost
|
|
gather_facts: true
|
|
vars_files:
|
|
- ../vars/defaults.yml
|
|
|
|
pre_tasks:
|
|
- name: capture — check existing spinifex.toml
|
|
ansible.builtin.stat:
|
|
path: "{{ spinifex_config_file }}"
|
|
register: reset_config_stat
|
|
|
|
- name: capture — slurp existing config
|
|
ansible.builtin.slurp:
|
|
src: "{{ spinifex_config_file }}"
|
|
register: reset_config_raw
|
|
when: reset_config_stat.stat.exists
|
|
|
|
- name: capture — decode config
|
|
ansible.builtin.set_fact:
|
|
reset_config_txt: "{{ reset_config_raw.content | b64decode }}"
|
|
when: reset_config_stat.stat.exists
|
|
|
|
# List-concat-and-take-first pattern: missing regex match falls back to current default.
|
|
# `gateway\s*=` deliberately does not match `gateway_ip` / `gateway_lrp_*`.
|
|
- name: capture — extract scalars
|
|
ansible.builtin.set_fact:
|
|
spinifex_region: "{{ (reset_config_txt | regex_findall('region\\s*=\\s*\"([^\"]+)\"') + [spinifex_region])[0] }}"
|
|
spinifex_az: "{{ (reset_config_txt | regex_findall('\\baz\\s*=\\s*\"([^\"]+)\"') + [spinifex_az])[0] }}"
|
|
spinifex_external_mode: "{{ (reset_config_txt | regex_findall('external_mode\\s*=\\s*\"([^\"]+)\"') + [spinifex_external_mode])[0] }}"
|
|
spinifex_external_pool_start: "{{ (reset_config_txt | regex_findall('range_start\\s*=\\s*\"([^\"]+)\"') + [spinifex_external_pool_start])[0] }}"
|
|
spinifex_external_pool_end: "{{ (reset_config_txt | regex_findall('range_end\\s*=\\s*\"([^\"]+)\"') + [spinifex_external_pool_end])[0] }}"
|
|
spinifex_external_gateway: "{{ (reset_config_txt | regex_findall('\\bgateway\\s*=\\s*\"([^\"]+)\"') + [spinifex_external_gateway])[0] }}"
|
|
spinifex_external_prefix_len: "{{ (reset_config_txt | regex_findall('prefix_len\\s*=\\s*([0-9]+)') + [spinifex_external_prefix_len | string])[0] }}"
|
|
spinifex_external_gateway_ip: "{{ (reset_config_txt | regex_findall('gateway_ip\\s*=\\s*\"([^\"]+)\"') + [spinifex_external_gateway_ip])[0] }}"
|
|
when: reset_config_stat.stat.exists
|
|
|
|
# Legacy: external_mode = "nat" was removed from spx. Coerce to "pool"
|
|
# so old configs still reset cleanly; warn so the operator notices.
|
|
- name: capture — coerce legacy external_mode=nat to pool
|
|
ansible.builtin.set_fact:
|
|
spinifex_external_mode: "pool"
|
|
when: spinifex_external_mode == 'nat'
|
|
|
|
- name: capture — warn on legacy nat coercion
|
|
ansible.builtin.debug:
|
|
msg: "⚠️ Captured external_mode=nat from legacy config; coerced to 'pool' (NAT mode removed from spx admin init)."
|
|
when:
|
|
- reset_config_stat.stat.exists
|
|
- (reset_config_txt | regex_findall('external_mode\\s*=\\s*\"nat\"')) | length > 0
|
|
|
|
- name: capture — summary
|
|
ansible.builtin.debug:
|
|
msg: |
|
|
{% if reset_config_stat.stat.exists %}
|
|
Captured settings from {{ spinifex_config_file }}:
|
|
region={{ spinifex_region }}, az={{ spinifex_az }}
|
|
external_mode={{ spinifex_external_mode }}
|
|
pool={{ spinifex_external_pool_start }}-{{ spinifex_external_pool_end }}
|
|
gateway={{ spinifex_external_gateway }}, prefix={{ spinifex_external_prefix_len }}
|
|
gateway_ip={{ spinifex_external_gateway_ip }}
|
|
{% else %}
|
|
No existing config; using defaults from vars/defaults.yml (or -e overrides).
|
|
{% endif %}
|
|
|
|
roles:
|
|
- teardown
|
|
- build
|
|
- install
|
|
- init
|
|
- smoketest
|