Skip to content

Commit 429d5a8

Browse files
committed
cloud-init update
1 parent 13f1b24 commit 429d5a8

File tree

10 files changed

+117
-1
lines changed

10 files changed

+117
-1
lines changed

cloud-init/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ docker build --tag vyos-vm-images:latest -f ./Dockerfile .
1111
```
1212
3. Start and connect to the container:
1313
```shell
14-
docker run --rm -it --privileged -v $(pwd):/vm-build -v $(pwd)/images:/tmp -w /vm-build vyos-vm-images:latest bash
14+
docker run --rm -it --privileged -v $(pwd):/vm-build -v $(pwd)/images:/images -w /vm-build vyos-vm-images:latest bash
1515
```
1616
4. Clone repo
1717
```

cloud-init/ansible/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generated/

cloud-init/ansible/ansible.cfg

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[defaults]
2+
inventory = ./hosts
3+
pipelining = True
4+
nocows = True

cloud-init/ansible/hosts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[local]
2+
localhost
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
instance-id: cloud
2+
local-hostname: vyos
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#cloud-config
2+
vyos_config_commands:
3+
- set system host-name '{{ item.name }}'
4+
- delete interfaces ethernet eth0 address
5+
- set interfaces ethernet eth0 address '{{ item.address }}/{{ item.prefix }}'
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
guests:
3+
- name: ci-r1
4+
cpu: 1
5+
mem: 1024
6+
virt_type: kvm
7+
virt_hypervisor: hvm
8+
os:
9+
variant: debian10
10+
disk:
11+
path: /var/lib/libvirt/images
12+
iface: eth0
13+
address: 192.168.122.31
14+
prefix: 24
15+
16+
- name: ci-r2
17+
cpu: 1
18+
mem: 1024
19+
virt_type: kvm
20+
virt_hypervisor: hvm
21+
os:
22+
variant: debian10
23+
disk:
24+
path: /var/lib/libvirt/images
25+
iface: eth0
26+
address: 192.168.122.32
27+
prefix: 24
28+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
- name: create VMs
3+
hosts: localhost
4+
gather_facts: no
5+
connection: local
6+
7+
vars:
8+
qcow_template: /home/sever/Downloads/ISO/vyos-1.4.0-cloud-init-2G-qemu.qcow2
9+
vars_files:
10+
- vars/guests_qcow.yml
11+
12+
tasks:
13+
- name: Get list of VMs
14+
virt:
15+
command: "list_vms"
16+
register: virt_vms
17+
18+
- name: Copy qcow2 from template "{{ qcow_template }}"
19+
become: true
20+
copy:
21+
src: "{{ qcow_template }}"
22+
dest: "{{ item.disk.path }}/{{ item.name }}.qcow2"
23+
when: item.name not in virt_vms.list_vms
24+
with_items: "{{ guests }}"
25+
26+
- name: Ensure generated/user-data directory exists
27+
ansible.builtin.file:
28+
path: "{{ playbook_dir }}/generated/user-data"
29+
state: directory
30+
31+
- name: Template user-data
32+
ansible.builtin.template:
33+
src: "{{ playbook_dir }}/templates/user-data.j2"
34+
dest: "{{ playbook_dir }}/generated/user-data/{{ item.name }}"
35+
with_items: "{{ guests }}"
36+
37+
- name: Create vm
38+
command: virt-install -n {{ item.name }}
39+
--ram {{ item.mem }}
40+
--vcpus {{ item.cpu }}
41+
--cloud-init "meta-data={{ playbook_dir }}/templates/meta-data,user-data={{ playbook_dir }}/generated/user-data/{{ item.name }}"
42+
--os-variant {{ item.os.variant }}
43+
--network network=default
44+
--graphics vnc
45+
--{{item.virt_hypervisor}}
46+
--virt-type {{ item.virt_type }}
47+
--disk path={{item.disk.path}}/{{item.name}}.qcow2,bus=virtio
48+
--import
49+
--noautoconsole
50+
when: item.name not in virt_vms.list_vms
51+
with_items: "{{ guests }}"
52+
53+
- name: make sure all vms are running
54+
virt:
55+
name: "{{ item.name }}"
56+
state: running
57+
with_items: "{{ guests }}"

cloud-init/deploy.sh renamed to cloud-init/deploy_with_seed.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#cp /tmp/vyos_raw_image.qcow2 /var/lib/libvirt/images/vyos_kvm.qcow2
44
cp vyos-1.4.0-cloud-init-2G-qemu.qcow2 /var/lib/libvirt/images/vyos_kvm.qcow2
5+
./generate_seed.sh
56

67
virt-install -n vyos_r1 \
78
--ram 2048 \

cloud-init/deploy_without_seed.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
cp vyos-1.4.0-cloud-init-2G-qemu.qcow2 /var/lib/libvirt/images/vyos_kvm.qcow2
4+
5+
virt-install -n vyos_r1 \
6+
--ram 4096 \
7+
--vcpus 2 \
8+
--cloud-init meta-data=meta-data,user-data=user-data \
9+
--os-variant debian10 \
10+
--network network=default \
11+
--graphics vnc \
12+
--hvm \
13+
--virt-type kvm \
14+
--disk path=/var/lib/libvirt/images/vyos_kvm.qcow2,bus=virtio \
15+
--import \
16+
--noautoconsole

0 commit comments

Comments
 (0)