Skip to content

Commit 9aa69ec

Browse files
committed
add a test for vm running
1 parent 527d6da commit 9aa69ec

File tree

4 files changed

+26
-74
lines changed

4 files changed

+26
-74
lines changed

README.md

Lines changed: 18 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ pip3 install docker-compose
114114

115115
## Build with Packer
116116

117-
Each JSON file is a template for a distribution :
117+
Each HCL file is a template for a distribution :
118118

119119
* [almalinux9.pkr.hcl](https://github.com/goffinet/packer-kvm/blob/master/almalinux9.pkr.hcl)
120120
* [almalinux10.pkr.hcl](https://github.com/goffinet/packer-kvm/blob/master/almalinux10.pkr.hcl)
@@ -132,6 +132,8 @@ For example :
132132
packer build almalinux9.pkr.hcl
133133
```
134134

135+
nota bene: those file are generated by the ansible playbook `build-packer-templates.yaml`.
136+
135137
## Build with Docker qemu based image
136138

137139
`goffinet/packer-qemu` is a Docker image for building qemu images with packer and is available on Docker Hub.
@@ -170,7 +172,7 @@ You can have more details from Packet with the env var configured : `PACKER_LOG=
170172

171173
## Cloud images for qemu/KVM/Libvirt built with Packer
172174

173-
I build images for qemu/KVM with this project and I [publish them](http://download.goffinet.org/kvm/index.html) for use in those other IaC projects: [Virt-scripts](https://github.com/goffinet/virt-scripts) and **[Terraform with Libvirt/KVM provider](https://github.com/goffinet/terraform-libvirt)**.
175+
I build images for qemu/KVM with this project and I [publish them](http://download.goffinet.org/kvm/index.html) for use in those other IaC projects: [Kcli](https://kcli.readthedocs.io/en/latest/#) or [Terraform with Libvirt/KVM provider](https://github.com/goffinet/terraform-libvirt).
174176

175177
- [almalinux9.qcow2](http://download.goffinet.org/kvm/almalinux9.qcow2) [[md5sum]](http://download.goffinet.org/kvm/almalinux9.qcow2.md5sum) [[sha256sum]](http://download.goffinet.org/kvm/almalinux9.qcow2.sha256sum)
176178
- [almalinux10.qcow2](http://download.goffinet.org/kvm/almalinux10.qcow2) [[md5sum]](http://download.goffinet.org/kvm/almalinux10.qcow2.md5sum) [[sha256sum]](http://download.goffinet.org/kvm/almalinux10.qcow2.sha256sum)
@@ -200,50 +202,22 @@ This is always beter to know how Libvirt is working. Can you read fundamentals a
200202

201203
### Enjoy with Libvirt
202204

203-
> _Switch to kcli_
204-
205-
<!--
206-
207-
[https://github.com/goffinet/virt-scripts](https://github.com/goffinet/virt-scripts)
208-
209-
1. Clone virt-scripts repo and prepare the machine
210-
211-
```bash
212-
sudo apt update && apt -y install git
213-
git clone https://github.com/goffinet/virt-scripts
214-
cd virt-scripts
215-
sudo ./autoprep.sh
216-
```
217-
218-
2. Build or download images
219-
220-
Put builded images in `/var/lib/libvirt/images` or download them :
205+
Please use the [kcli](https://kcli.readthedocs.io/en/latest/#) project.
221206

222-
```bash
223-
sudo ./download-images.sh
224-
```
225-
```raw
226-
Please provide the image name :
227-
almalinux9 almalinux10 centos9 debian12 fedora40 rocky9 rocky10 ubuntu2404
228-
```
207+
For example:
229208

230-
3. Launch two new machines
231-
232-
```bash
233-
sudo ./define-guest-image.sh c1 almalinux9
234-
sudo ./define-guest-image.sh u1 ubuntu2404
235-
```
236-
237-
4. Enjoy
238-
239-
```bash
240-
sudo virsh console u1
241-
```
242-
243-
```bash
244-
ssh $(dig @192.168.122.1 +short u1)
245-
```
246-
-->
209+
```bash
210+
image="almalinux10"
211+
# Get kcli tool
212+
curl https://raw.githubusercontent.com/karmab/kcli/main/install.sh | sudo bash
213+
# Get the image
214+
kcli download image -P url=http://download.goffinet.org/kvm/${image}.qcow2 ${image}
215+
# Create a test vm
216+
kcli create vm -i ${image} -P memory=2048 -P numcpus=1 -P disks=[50] ${image}
217+
# Test SSH connexion and delete the test VM
218+
chmod 600 sshkeys/id_rsa
219+
sleep 30 && if [ "$(kcli ssh -u root -i sshkeys/id_rsa ${image} 'echo test')" == "test" ] ; then echo SUCCESS ; else echo ERROR ; kcli delete vm -y ${image} ; fi
220+
```
247221

248222
### Enjoy with Terraform (with libvirt)
249223

roles/build_packer_templates/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ To use this role, include it in your Ansible playbook and provide the necessary
6262
This role supports the following operating system versions for building Packer templates:
6363

6464
- **Red Hat-based Systems:**
65-
- AlmaLinux: 9
66-
- Rocky: 9
67-
- CentOS Stream: 9, 10
65+
- AlmaLinux: 9, 10
66+
- Rocky: 9, 10
67+
- CentOS Stream: 9
6868
- Fedora: 40
6969

7070
- **Debian-based Systems:**
71-
- Ubuntu: 20.04, 22.04, 24.04
71+
- Ubuntu: 24.04
7272
- Debian: 12
7373

7474
## Example Playbook

scripts/push-image.sh

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,27 +37,6 @@ size_image=$(stat -c %s ${image}.qcow2)
3737
md5sum ${image}.qcow2 > ${image}.qcow2.md5sum
3838
sha256sum ${image}.qcow2 > ${image}.qcow2.sha256sum
3939

40-
## Test the image with kcli.
41-
# Get kcli tool
42-
curl https://raw.githubusercontent.com/karmab/kcli/main/install.sh | sudo bash
43-
# Get the image
44-
kcli download image -P url=file://${PWD}/${image}.qcow2 ${image}
45-
# Create a test vm
46-
kcli create vm -i ${image} -P memory=2048 -P numcpus=1 -P disks=[50] ${image}
47-
# Test SSH connexion and delete the test VM
48-
chmod 600 ../../../sshkeys/id_rsa
49-
sleep 30
50-
if [ "${name}" == "ubuntu" ] ; then
51-
user="ubuntu"
52-
else
53-
user="root"
54-
fi
55-
if [ "$(kcli ssh -u ${user} -i ../../../sshkeys/id_rsa ${image} 'echo test')" == "test" ] ; then
56-
echo SUCCESS ; kcli delete vm -y ${image}
57-
else
58-
echo ERROR ; kcli delete vm -y ${image} ; exit 1
59-
fi
60-
6140
# create a https://gns3.com appliance file
6241

6342
cat << EOF > ${image}.gns3a

test_vm.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,27 @@
11
#!/bin/bash
22

3-
43
image=$1
54
if [ -z "$image" ]; then
6-
echo "Erreur : aucune image fournie."
5+
echo "No image specified. Usage: $0 $(cat imagename)"
76
exit 1
87
fi
98
name=$(echo "$image" | tr -d '0-9.')
109
## Test the image with kcli.
1110
# Get kcli tool
1211
curl https://raw.githubusercontent.com/karmab/kcli/main/install.sh | sudo bash
1312
# Get the image
14-
kcli download image -P url=file://${PWD}/${image}.qcow2 ${image}
13+
kcli download image -P url=http://download.goffinet.org/kvm/${image}.qcow2 ${image}
1514
# Create a test vm
1615
kcli create vm -i ${image} -P memory=2048 -P numcpus=1 -P disks=[50] ${image}
1716
# Test SSH connexion and delete the test VM
18-
chmod 600 ../../../sshkeys/id_rsa
17+
chmod 600 sshkeys/id_rsa
1918
sleep 30
2019
if [ "${name}" == "ubuntu" ] ; then
2120
user="ubuntu"
2221
else
2322
user="root"
2423
fi
25-
if [ "$(kcli ssh -u ${user} -i ../../../sshkeys/id_rsa ${image} 'echo test')" == "test" ] ; then
24+
if [ "$(kcli ssh -u ${user} -i sshkeys/id_rsa ${image} 'echo test')" == "test" ] ; then
2625
echo SUCCESS ; kcli delete vm -y ${image}
2726
else
2827
echo ERROR ; kcli delete vm -y ${image} ; exit 1

0 commit comments

Comments
 (0)