---
# tasks file for roles/init_lxd
- name: Install lxd
  become: true
  ansible.builtin.snap:
    name: lxd
    classic: yes

- register: tmp_file_stat
  stat: path="{{lxd_init_template_processed_path}}"
- ansible.builtin.meta: end_batch
  when: tmp_file_stat.stat.exists

- ansible.builtin.debug:
    var: hostvars[inventory_hostname]['ansible_default_ipv4']['address']
    verbosity: 1

#- delegate_to: localhost
#  delegate_facts: true
#  ansible.builtin.copy:
#    content: "{{hostvars[inventory_hostname]}}"
#    dest: ./test.json

- delegate_to: localhost
  delegate_facts: true
  ansible.builtin.template:
    src: "{{lxd_init_template_config_path}}"
    dest: "{{lxd_init_template_processed_path}}"

## tira el lxd init con los parametros
- name: "Preseeding LXD Init with template: {{lxd_init_template_config_path}}"
  become: true
  ansible.builtin.shell: |
    cat <<EOF | lxd init --preseed
    {{ lookup('file', lxd_init_template_processed_path) }}
    EOF
  register: lxd_init_output

- ansible.builtin.debug:
    var: lxd_init_output