-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup-multipass.yaml
43 lines (42 loc) · 1.53 KB
/
setup-multipass.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
- hosts: localhost
tasks:
- name: Create VM in multipass
command: multipass launch --name {{ item }}
with_sequence: start=1 count=3 format=consul-nomad-%02x
register: create_vm
ignore_errors: yes
- name: Add SSH authorized_keys to VM
shell: cat id_ed25519.pub | multipass exec {{ item }} -- tee -a .ssh/authorized_keys
with_sequence: start=1 count=3 format=consul-nomad-%02x
when: create_vm.failed is not true
- name: Generate ansible repository(host) file
shell: "{{ item }}"
with_items:
- echo [server] | tee hosts
- multipass list --format json | jq -r '.list[] | (.name+" ansible_host="+.ipv4[0])' >> hosts
when: create_vm.failed is not true
- name: Generate ansible repository(host) file
shell: "{{ item }}"
with_items:
- multipass list --format json | jq -r '.list[].ipv4[0]'
register: server_ip
- name: View variable
debug:
msg: "{{ server_ip }}"
- name: Add server fingerprint to known_hosts
command: ssh -o "StrictHostKeyChecking=accept-new" ubuntu@{{ item }}
with_items: "{{server_ip.results[0].stdout_lines}}"
- name: Wait for SSH port available on server
wait_for:
host: "{{ item }}"
port: 22
delay: 5
timeout: 300
with_items: "{{server_ip.results[0].stdout_lines}}"
- name: Delete VM in multipass
command: multipass delete {{ item }}
with_sequence: start=1 count=3 format=consul-nomad-%02x
tags: ["never", "delete"]
- name: Purge VM multipass
command: multipass purge
tags: ["never", "delete"]