---
# Ansible playbook generated by Vibe Infra
- name: {{ spec.get('playbook_name', 'Generated Playbook') }}
  hosts: {{ hosts }}
  {% if become %}
  become: yes
  {% endif %}

  {% if vars %}
  vars:
    {% for key, value in vars.items() %}
    {{ key }}: {{ value | tojson }}
    {% endfor %}
  {% endif %}

  tasks:
    {% for task in tasks %}
    - name: {{ task.name }}
      {% for module, params in task.items() if module != 'name' %}
      {{ module }}:
        {% if params is mapping %}
        {% for key, value in params.items() %}
        {{ key }}: {{ value | tojson }}
        {% endfor %}
        {% else %}
        {{ params }}
        {% endif %}
      {% endfor %}
      {% if task.get('tags') %}
      tags:
        {% for tag in task.tags %}
        - {{ tag }}
        {% endfor %}
      {% endif %}
    {% endfor %}

    # Mark as managed by Vibe Infra
    - name: Record athena management
      ansible.builtin.file:
        path: /var/log/athena-managed
        state: touch
        mode: '0644'
      tags: [metadata]
