59 lines
2.3 KiB
YAML
59 lines
2.3 KiB
YAML
|
---
|
||
|
## -------------------------- ##
|
||
|
## Build or Restore Instance ##
|
||
|
## -------------------------- ##
|
||
|
|
||
|
- name: check invalid create mode
|
||
|
when: lxd.instance.create_mode | mandatory not in ['skip', 'build']
|
||
|
ansible.builtin.fail:
|
||
|
msg: "invalid lxd.instance.create_mode: {{ lxd.instance.create_mode }}"
|
||
|
|
||
|
- name: handle create instance
|
||
|
when: lxd.instance.create_mode == 'build'
|
||
|
block:
|
||
|
|
||
|
- name: clear pre-existing instance
|
||
|
with_items:
|
||
|
- container
|
||
|
- virtual-machine
|
||
|
community.general.lxd_container:
|
||
|
name: "{{ lxd.instance.name | mandatory }}"
|
||
|
type: "{{ item }}"
|
||
|
state: absent
|
||
|
force_stop: true
|
||
|
# XXX: ansible will always indicate a change when volatile options are present in the LXD config
|
||
|
ignore_volatile_options: false
|
||
|
|
||
|
- name: define custom instance configuration 'lxd_custom_config'
|
||
|
ansible.builtin.include_tasks: instance_config.yml
|
||
|
|
||
|
- name: merge and override instance base config with custom config
|
||
|
when: lxd.instance.config is defined
|
||
|
ansible.builtin.set_fact:
|
||
|
lxd_custom_config: "{{ ( lxd.instance.config ) | combine(lxd_custom_config | default({}), recursive=True) }}"
|
||
|
|
||
|
- name: create & (re)start instance
|
||
|
community.general.lxd_container:
|
||
|
name: "{{ lxd.instance.name }}"
|
||
|
type: "{{ lxd.instance.type | default(omit) }}"
|
||
|
state: restarted
|
||
|
source:
|
||
|
server: "{{ lxd.instance.server | default('https://images.linuxcontainers.org') }}"
|
||
|
alias: "{{ lxd.instance.alias | mandatory }}"
|
||
|
# 'simplestreams' seems more reliable than the default protocol 'lxd'
|
||
|
protocol: "{{ lxd.instance.protocol | default('simplestreams') }}"
|
||
|
type: image
|
||
|
mode: pull
|
||
|
# XXX: ansible will always indicate a change when volatile options are present in the LXD config
|
||
|
ignore_volatile_options: false
|
||
|
config: "{{ lxd_custom_config | default(omit) }}"
|
||
|
devices: "{{ lxd.instance.devices | default(omit) }}"
|
||
|
profiles: "{{ lxd.instance.profiles | default(omit) }}"
|
||
|
wait_for_ipv4_addresses: true
|
||
|
timeout: 600
|
||
|
|
||
|
- name: "wait for {{ lxd.instance.name }} to respond with SSHd"
|
||
|
ansible.builtin.wait_for:
|
||
|
host: "{{ lxd.instance.dns_address | mandatory }}"
|
||
|
port: 22
|