--- ## ------------------------------------------------ ## ## Installs LXD (includes LXC), and default profile ## ## ------------------------------------------------ ## #- name: install snapd # ansible.builtin.package: # name: snapd #- name: install snap core # community.general.snap: # name: core # XXX: simplest way to void a prior LXD installation's configuration #- name: uninstall prior LXD # ansible.builtin.command: snap remove lxd --purge # changed_when: true - name: clear preseed storage_pools loop: "{{ lxd.host.preseed.storage_pools | default([]) }}" loop_control: loop_var: lxd_storage_pool ansible.builtin.include_tasks: reset_storage.yml #- name: install LXD # become: true # community.general.snap: # name: lxd - name: check LXD executable accessible by Ansible ansible.builtin.shell: which lxd ignore_errors: true register: which_lxd - name: install LXD wrapper when: which_lxd is failed vars: lxd_path: /snap/bin/lxd block: - name: verify snap lxd installation exists ansible.builtin.stat: path: "{{ lxd_path }}" get_checksum: false register: lxd_stat failed_when: not lxd_stat.stat.exists - name: create lxd wrapper if lxd is not in PATH ansible.builtin.template: src: wrapper.sh.j2 dest: /usr/bin/lxd owner: root group: root mode: u=rx,g=rx,o=rx vars: snap_app: lxd snap_app_path: "{{ lxd_path }}" - name: check LXC executable accessible by Ansible ansible.builtin.shell: which lxc ignore_errors: true changed_when: false register: which_lxc - name: install LXD wrapper when: which_lxc is failed vars: lxc_path: /snap/bin/lxc block: - name: detect if lxc is in PATH ansible.builtin.stat: path: "{{ lxc_path }}" get_checksum: false register: lxc_stat failed_when: not lxc_stat.stat.exists - name: create lxc wrapper if lxc is not in PATH ansible.builtin.template: src: wrapper.sh.j2 dest: /usr/bin/lxc owner: root group: root mode: u=rx,g=rx,o=rx vars: snap_app: lxc snap_app_path: "{{ lxc_path }}" - name: init LXD without preseed when: not lxd.host.preseed is defined ansible.builtin.command: lxd init --auto - name: init LXD from preseed when: lxd.host.preseed is defined ansible.builtin.command: "lxd init --preseed < " args: stdin: "{{ lxd.host.preseed }}" - name: apply extra profiles loop: "{{ lxd.host.extra_profiles | default([]) }}" loop_control: loop_var: lxd_profile community.general.lxd_profile: name: "{{ lxd_profile.name | mandatory }}" description: "{{ lxd_profile.description | default(omit) }}" state: "{{ lxd_profile.state | default(omit) }}" config: "{{ lxd_profile.config | default(omit) }}" devices: "{{ lxd_profile.devices | default(omit) }}"