Skip to content

Commit

Permalink
Use native LXD module for cloning containers
Browse files Browse the repository at this point in the history
  • Loading branch information
oskar456 committed Apr 28, 2021
1 parent 65c5ebd commit 935c0dd
Showing 1 changed file with 9 additions and 26 deletions.
35 changes: 9 additions & 26 deletions ansible/site.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@
lxd_container:
name: hostA
state: started
config:
volatile.eth0.hwaddr: "00:16:3e:ee:00:0a"
source:
type: image
mode: pull
server: https://images.linuxcontainers.org
protocol: lxd # if you get a 404, try setting protocol: simplestreams
alias: ubuntu/focal/amd64
volatile.eth0.hwaddr: "00:16:3e:ee:00:0a"
protocol: simplestreams
alias: ubuntu/focal
profiles: ["default"]
wait_for_ipv4_addresses: true

Expand Down Expand Up @@ -117,40 +118,22 @@
when: compile_thc.changed

- name: Clone container
command:
cmd: "lxc cp hostA {{ item }}"
creates: "/var/lib/lxd/containers/{{ item }}"
register: cloned
with_items:
- hostB
- hostC

- name: Setup static MAC address
lxd_container:
name: "{{ item.name }}"
config:
volatile.eth0.hwaddr: "{{ item.mac }}"
state: started
when: cloned.changed
register: staticmac
source:
type: copy
source: hostA
profiles: ["default"]
wait_for_ipv4_addresses: true
with_items:
- name: hostA
mac: 00:16:3e:ee:00:0a
- name: hostB
mac: 00:16:3e:ee:00:0b
- name: hostC
mac: 00:16:3e:ee:00:0c

- name: Restart containers
lxd_container:
name: "{{ item.name }}"
state: restarted
when: staticmac.changed
with_items:
- name: hostA
- name: hostB
- name: hostC

- name: Host provision
hosts: default
become: true
Expand Down

0 comments on commit 935c0dd

Please sign in to comment.