homelab/ansible/archive/playbooks/generate_inventory.yml

29 lines
978 B
YAML

---
# Generate `ansible/inventory/hosts.ini` from the central YAML SoT
# Run locally: `ansible-playbook ansible/playbooks/generate_inventory.yml --connection=local`
- name: Generate inventory from central source of truth
hosts: localhost
connection: local
gather_facts: false
vars:
sod_file: "../group_vars/all.yml"
inventory_dest: "../inventory/hosts.ini"
tasks:
- name: Generate inventory file using local script
ansible.builtin.command: "python3 ../scripts/generate_inventory.py --sot {{ sod_file }} --out /tmp/generated_hosts.ini"
args:
chdir: "{{ playbook_dir }}"
changed_when: false
- name: Install generated inventory with backup
ansible.builtin.copy:
src: /tmp/generated_hosts.ini
dest: "{{ inventory_dest }}"
mode: '0644'
backup: true
- name: Show result path
ansible.builtin.debug:
msg: "Wrote inventory to {{ inventory_dest }} (backup created if present)"