Skip to content

Commit 4f2b74c

Browse files
committed
Initial commit.
0 parents  commit 4f2b74c

23 files changed

+910
-0
lines changed

.ansible-lint

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
skip_list:
2+
- 'risky-shell-pipe'
3+
- 'role-name'

.gitignore

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.DS_Store
2+
.idea
3+
build
4+
tmp
5+
6+
*~
7+
.*.swp
8+
*.bak
9+
10+
*.iso
11+
*.img
12+
*.pub
13+
*.iml

.travis.yml

Whitespace-only changes.

LICENSE

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BSD 3-Clause License
2+
3+
Copyright (c) 2022, Vladislav V. Prodan
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice, this
10+
list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright notice,
13+
this list of conditions and the following disclaimer in the documentation
14+
and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
# linux_run_iso_in_qemu
2+
3+
[Ansible Galaxy](https://galaxy.ansible.com/click0/linux_run_iso_in_qemu/)
4+
5+
Linux. Running QEMU with (or without) ISO and connecting block devices (HDD/SSD) of the host machine.
6+
Feel free to [share your feedback and report issues](https://github.com/click0/ansible-linux-run-iso-in-qemu/issues).
7+
[Contributions are welcome](https://github.com/firstcontributions/first-contributions).
8+
9+
## Synopsis
10+
11+
Many Datacenters and Hosters have removed the OS installation from their media (ISO).
12+
And, most generally offer very little choice - Debian, Ubuntu, CentOS and nothing else.
13+
This role will allow you to run the QEMU program with the Rescue server mode.
14+
[QEMU](https://www.qemu.org/) allows us to emulate a virtual machine, to which we will connect the ISO as a CD-ROM and connecting block devices (HDD/SSD) of the host machine.
15+
The role uses QEMU of two types - from the package base of the system and universal binary for Linux with statically compiled libraries.
16+
The ISO can be used as your favorite OS install disk, diagnostic disk, or other live operating system ([Live-CD](https://en.wikipedia.org/wiki/Live_CD))
17+
Sources for obtaining ISO and QEMU universal binary - local system running Ansible, Rescue server mode itself and ftp/http(s).
18+
19+
There is no Internet inside the system running inside QEMU yet, but we will fix this in the next release.
20+
To increase security for access to the system in QEMU, you can specify a whitelist of IP/networks through the `iptables` firewall.
21+
22+
## Requirements
23+
24+
Linux system Debian or CentOS.
25+
Installed packages:
26+
- python3
27+
- python3-apt
28+
29+
## Variables
30+
31+
See the `defaults/main.yml` and examples in vars:
32+
33+
lisoq_qemu_enable: false
34+
Do I need to use and run QEMU. Without this option, the role can download the ISO and configure the firewall.
35+
36+
lisoq_qemu_static_custom_enable: false
37+
The option is responsible for using (or not) universal binary for Linux with statically compiled libraries.
38+
If this variable is selected, then the other variable `lisoq_qemu_install` will be disabled by the role itself.
39+
40+
lisoq_qemu_static_custom_local: ''
41+
The local path on the Ansible host to the statically compiled QEMU archive(tar.gz).
42+
43+
lisoq_qemu_static_custom_url: 'https://support.org.ua/Soft/vKVM/orig/vkvm.tar.gz'
44+
URL location with the statically compiled QEMU archive(tar.gz).
45+
46+
lisoq_qemu_static_custom_relative_dir: '/share/qemu/'
47+
Relative path inside the statically compiled QEMU archive to auxiliary files (BIOS, keyboard layout etc).
48+
49+
lisoq_qemu_static_custom_uefi_url: 'https://support.org.ua/Soft/vKVM/orig/uefi.tar.gz'
50+
Auxiliary UEFI BIOS archive URL to support block devices larger than 2 TiB.
51+
52+
lisoq_qemu_args_port_ssh: '1022'
53+
External port for ssh forwarding to QEMU internal port `22`.
54+
55+
lisoq_qemu_args_port_rdp: '3389'
56+
External port for RDP forwarding to internal QEMU port `3389`
57+
58+
lisoq_qemu_args_port_vnc: '5901'
59+
External port for forwarding VNC to internal QEMU port `5901`
60+
61+
lisoq_qemu_vnc_type: 'local'
62+
The variable controls how QEMU will "listen" for VNC connections.
63+
The value of the `local` variable is to listen only on `localhost`.
64+
The value of the `share` variable is to listen on all IPs.
65+
66+
lisoq_qemu_install: false
67+
Install QEMU from the package repository.
68+
69+
lisoq_qemu_ram: '1024'
70+
How much RAM (in MiB) can you use inside QEMU.
71+
72+
lisoq_qemu_cpu: ''
73+
How much CPU core can you use inside QEMU. By default `''` and role allocates all CPU cores for QEMU use.
74+
75+
lisoq_qemu_disk: ''
76+
List of block disk devices to connect to QEMU. By default, the role mounts all found block devices from the host machine.
77+
You can specify your own list of block devices:
78+
79+
lisoq_qemu_disk:
80+
- 'sda'
81+
- 'sdb'
82+
<br>
83+
84+
lisoq_qemu_exclude_disk:
85+
- 'fd0'
86+
- 'sr0'
87+
88+
List of block disk devices to be excluded from the `lisoq_qemu_disk` list. The exclusion list usually contains FDD and CD-ROM devices.
89+
90+
lisoq_qemu_boot_cd: true
91+
Whether to boot QEMU from CD-ROM (from our downloaded ISO file `lisoq_iso_file_...` ).
92+
93+
lisoq_qemu_boot_once_cd: true
94+
Whether to download _**once**_ from CD-ROM (from our downloaded ISO file `lisoq_iso_file_...` ).
95+
Inside QEMU, you can choose to `reboot` the virtual machine and then the system will try to boot from the HDDs, _not_ from the CD-ROM.
96+
To use service CDs where there is a large set of applications, and the need to reboot the virtual machine frequently, set the value to `false`.
97+
98+
lisoq_iso_file_local: ''
99+
Full path to the ISO file on the host machine from which the Ansible role is run. There is support for symlinks and share partitions mounted on the host machine file system.
100+
101+
lisoq_iso_file_remote: ''
102+
ISO file location path on a remote host.
103+
104+
lisoq_iso_file_url: 'https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-12.2-RELEASE-amd64.iso'
105+
URL location with ISO file.
106+
107+
lisoq_iso_file_ssh_port: '22'
108+
Sshd port that accepts connections _inside_ ISO.
109+
110+
lisoq_ramdisk_enable: false
111+
Use (and create) RAM-disk partitions on the target system (before running QEMU).
112+
113+
lisoq_ramdisk_location: '/mnt'
114+
The preferred path for the RAM-disk partition.
115+
116+
lisoq_ramdisk_another_location: '/tmp'
117+
The alternative path for a RAM-disk partition if it is already in use internally. Subsequently, we will expand it to the desired size.
118+
119+
lisoq_ramdisk_existed: false
120+
Detect flag if RAM-disk partition is already in use. Service (local) variable.
121+
122+
lisoq_ramdisk_mounted: false
123+
Detect flag if RAM-disk partition is already in mounted. Service (local) variable.
124+
125+
lisoq_ramdisk_size: '300'
126+
The size of the RAM-disk partition in MiB (mebibytes).
127+
128+
lisoq_total_need_ram: "( {{ lisoq_ramdisk_size | int + lisoq_qemu_ram | int }} | default('300') )"
129+
The minimum amount of RAM on the target system in MiB (mebibytes). The sum of two components - `lisoq_ramdisk_size` and `lisoq_qemu_ram`.
130+
131+
lisoq_firewall_acl_enable: false
132+
Allow ACLs to whitelist IP's/net's and some listening ports (for example, `{{ lisoq_qemu_args_port_ssh }}` and `{{ lisoq_qemu_args_port_vnc }}`). Connections from other IPs to these ports are dropped. Whitelists are separate for IPv4 and IPv6 networks.
133+
134+
lisoq_firewall_acl_ipv4_white:
135+
- '127.0.0.0/8'
136+
Default white list for IPv4 networks.
137+
138+
lisoq_firewall_acl_ipv6_white:
139+
- '::1/128'
140+
Default white list for IPv6 networks.
141+
142+
lisoq_firewall_acl_ports:
143+
- '{{ lisoq_qemu_args_port_ssh | default(omit) }}'
144+
- '{{ lisoq_qemu_args_port_rdp | default(omit) }}'
145+
- '{{ lisoq_qemu_args_port_vnc | default(omit) }}'
146+
Default port ACL for a firewall.
147+
148+
lisoq_qemu_args: '
149+
-net nic
150+
-rtc base=localtime
151+
-M pc
152+
-vga std
153+
-daemonize
154+
'
155+
List of required command line arguments to run QEMU.
156+
157+
## Workflow
158+
159+
1) Install the role
160+
161+
```
162+
shell> ansible-galaxy role install click0.linux_run_iso_in_qemu
163+
```
164+
165+
2) Look variables, e.g. in `defaults/main.yml`
166+
167+
You can override them in the playbook and inventory.
168+
169+
## Example Playbooks
170+
171+
### Example #1
172+
173+
- hosts: rescue_servers
174+
vars_files:
175+
- vars/main.yml
176+
roles:
177+
- click0.linux_run_iso_in_qemu
178+
*Inside `vars/main.yml`*:
179+
180+
lisoq_qemu_enable: true
181+
lisoq_qemu_static_custom_enable: true
182+
lisoq_iso_file_url: 'https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-12.2-RELEASE-amd64.iso'
183+
lisoq_firewall_acl_ipv4_white:
184+
- '127.0.0.0/8'
185+
- '10.0.0.0/8'
186+
- '192.168.0.0/16'
187+
lisoq_firewall_acl_ipv6_white: []
188+
lisoq_firewall_acl_enable: true
189+
190+
### Example #2
191+
192+
- hosts: rescue_servers
193+
vars_files:
194+
- vars/main.yml
195+
roles:
196+
- click0.linux_run_iso_in_qemu
197+
*Inside `vars/main.yml`*:
198+
199+
lisoq_qemu_enable: true
200+
lisoq_qemu_install: true
201+
lisoq_qemu_ram: '1000'
202+
lisoq_qemu_cpu: '2'
203+
lisoq_iso_file_local: '../../files/ISO images/WinPE10_8_Strelec_2022.01.04.iso'
204+
lisoq_qemu_vnc_type: 'share'
205+
lisoq_ramdisk_enable: true
206+
lisoq_ramdisk_size: '4100'
207+
lisoq_firewall_acl_ipv4_white:
208+
- '127.0.0.0/8'
209+
- '10.0.0.0/8'
210+
- '192.168.0.0/16'
211+
lisoq_firewall_acl_enable: true
212+
213+
## TODO
214+
215+
- [ ] Test on a Linux LiveCD based:
216+
- Debian
217+
- CentOS
218+
- Rocky Linux
219+
- Alpine
220+
- ArchLinux
221+
- OpenWRT
222+
- [ ] Set up Internet access inside QEMU
223+
224+
## Tested
225+
226+
- [x] Freshly installed on HDD a Debian "bullseye" 11
227+
228+
## Dependencies
229+
230+
None.
231+
232+
## Further use
233+
234+
### License
235+
236+
BSD 3-Clause
237+
238+
### Author:
239+
240+
- Vladislav V. Prodan `<github.com/click0>`
241+
242+
### 🤝 Contributing
243+
244+
Contributions, issues and feature requests are welcome!<br>
245+
Feel free to check [issues page](https://github.com/click0/ansible-linux-run-iso-in-qemu/issues).
246+
247+
### Show your support
248+
249+
Give a ⭐ if this project helped you!
250+
251+
<a href="https://www.buymeacoffee.com/click0" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-orange.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

defaults/main.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
3+
lisoq_qemu_enable: false
4+
5+
lisoq_qemu_static_custom_enable: false
6+
lisoq_qemu_static_custom_url: 'https://support.org.ua/Soft/vKVM/orig/vkvm.tar.gz' # from url archive
7+
8+
# Mirrors
9+
# - https://support.org.ua/Soft/vKVM/orig/vkvm.tar.gz
10+
# - https://cdn.rodney.io/content/blog/files/vkvm.tar.gz
11+
# - https://abcvg.ovh/uploads/need/vkvm-latest.tar.gz
12+
# - https://depenguin.me/files/vkvm.tar.gz
13+
14+
lisoq_qemu_static_custom_local: '' # local file (archive tar.gz) in Ansible host
15+
lisoq_qemu_static_custom_relative_dir: '/share/qemu/'
16+
lisoq_qemu_static_custom_uefi_url: 'https://support.org.ua/Soft/vKVM/orig/uefi.tar.gz' # from url archive
17+
lisoq_qemu_args_port_ssh: '1022' # ssh port forwarding
18+
lisoq_qemu_args_port_rdp: '3389' # RDP port forwarding
19+
lisoq_qemu_args_port_vnc: '5901' # VNC port forwarding
20+
lisoq_qemu_vnc_type: 'local' # or 'share' # or 'socket' ????
21+
lisoq_qemu_install: false
22+
lisoq_qemu_ram: '1024' # in MiB (mebibyte)
23+
lisoq_qemu_cpu: '' # all CPU - autodetect
24+
lisoq_qemu_disk: '' # default - autodetect
25+
# - 'sda'
26+
# - 'sdb'
27+
lisoq_qemu_exclude_disk:
28+
- 'fd0'
29+
- 'sr0'
30+
lisoq_qemu_boot_cd: true
31+
lisoq_qemu_boot_once_cd: true
32+
33+
lisoq_iso_file_local: '' # local file in Ansible host
34+
lisoq_iso_file_remote: '' # file in target host
35+
lisoq_iso_file_url: 'https://mfsbsd.vx.sk/files/iso/12/amd64/mfsbsd-12.2-RELEASE-amd64.iso'
36+
lisoq_iso_file_ssh_port: '22' # sshd port that accepts connections _inside_ ISO.
37+
38+
lisoq_ramdisk_enable: false
39+
lisoq_ramdisk_location: '/mnt'
40+
lisoq_ramdisk_another_location: '/tmp'
41+
lisoq_ramdisk_existed: false
42+
lisoq_ramdisk_mounted: false
43+
lisoq_ramdisk_size: '300' # in MiB (mebibyte)
44+
45+
lisoq_total_need_ram: "( {{ lisoq_ramdisk_size | int + lisoq_qemu_ram | int }} | default('300') )"
46+
47+
lisoq_firewall_acl_enable: false # ACL to the ports {{ lisoq_qemu_args_port_ssh }} and {{ lisoq_qemu_args_port_vnc }}
48+
lisoq_firewall_acl_ipv4_white:
49+
- '127.0.0.0/8'
50+
lisoq_firewall_acl_ipv6_white:
51+
- '::1/128'
52+
53+
lisoq_firewall_acl_ports:
54+
- '{{ lisoq_qemu_args_port_ssh | default(omit) }}'
55+
- '{{ lisoq_qemu_args_port_rdp | default(omit) }}'
56+
- '{{ lisoq_qemu_args_port_vnc | default(omit) }}'
57+
58+
lisoq_qemu_args: '
59+
-net nic
60+
-rtc base=localtime
61+
-M pc
62+
-vga std
63+
-daemonize
64+
'

handlers/main.yml

Whitespace-only changes.

meta/main.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
galaxy_info:
3+
namespace: click0
4+
role_name: linux_run_iso_in_qemu
5+
author: Vladislav V. Prodan
6+
description: Linux. Running QEMU with (or without) ISO and connecting block devices (HDD/SSD) of the host machine.
7+
company: https://support.od.ua
8+
github_branch: master
9+
license: BSD
10+
min_ansible_version: '2.11'
11+
platforms:
12+
- name: 'Debian'
13+
versions: ['all']
14+
galaxy_tags:
15+
- linux
16+
- system
17+
- run
18+
- rescue
19+
- qemu
20+
- iso
21+
dependencies: []
22+
collections: []
23+
...

0 commit comments

Comments
 (0)