Using composer, libvirt, QEMU, virsh and some Ansible.
Below, a test deployment of a RHEL8 VM. It's available for SSH within less than 7 seconds. Follow the instructions below to do this yourself. Feel free to contribute improvements to rhel8-base.toml and qcow2.ks if you manage to optimize anything.
[mglantz@darkred templates]$ time sudo c_vm mtest15
Formatting '/var/lib/libvirt/images/mtest15.qcow2', fmt=qcow2 size=16106127360 backing_file=/home/mglantz/code/ansible/vm/rhel8-base-0.6.0.qcow2 cluster_size=65536 lazy_refcounts=off refcount_bits=16
Domain mtest15 created from /home/mglantz/code/ansible/vm/templates/mtest15.xml
IP-ADDRESS OF SYSTEM: 192.168.122.181
[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost
does not match 'all'
PLAY [Provision VM] *************************************************************************************
TASK [Debug] ********************************************************************************************
ok: [localhost] => {
"msg": "IP of VM is: 192.168.122.181"
}
TASK [Add host into in-memory inventory] ****************************************************************
changed: [localhost]
TASK [Check so that server is online] *******************************************************************
ok: [localhost]
PLAY RECAP **********************************************************************************************
localhost : ok=3 changed=1 unreachable=0 failed=0
real 0m6.663s
user 0m1.041s
sys 0m0.223s
- Install a RHEL8 server
- Install the following software to be able to build a qcow2 disk image with RHEL8
dnf install -y dnf-utils createrepo_c composer-cli lorax-composer httpd git
- Enable and start Apache web server
systemctl enable httpd
systemctl start httpd
- Sync RHEL8 to your RHEL8 composer server:
reposync -n -p /var/www/html --repoid rhel-8-for-x86_64-baseos-htb-rpms --downloadcomps --download-metadata
reposync -n -p /var/www/html --repoid rhel-8-for-x86_64-appstreams-htb-rpms --downloadcomps --download-metadata
- Disable all repos from RHN on your server
subscription-manager repos disable=*
- Create repos
createrepo -v /var/www/html/rhel-8-for-x86_64-baseos-htb-rpms/ -g $(ls /var/www/html/rhel-8-for-x86_64-baseos-htb-rpms/repodata/*comps.xml)
createrepo -v /var/www/html/rhel-8-for-x86_64-apptreams-htb-rpms/ -g $(ls /var/www/html/rhel-8-for-x86_64-appstreams-htb-rpms/repodata/*comps.xml)
- Create local repository files which points to your local repos which you've now created
cat << 'EOF' >/etc/yum.repos.d/rhel.repo
[baseos-rpms]
name=baseos-rpms
baseurl=http://localhost/rhel-8-for-x86_64-baseos-htb-rpms
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
[appstream-rpms]
name=appstream-rpms
baseurl=http://localhost/rhel-8-for-x86_64-appstream-htb-rpms
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
- Clone this git repository
git clone http://github.com/mglantz/c_vm
- Replace qcow2.ks with the one from this repo.
cp c_vm/qcow2.ks /usr/share/lorax/composer/qcow2.ks
- Generate a SSH key and put it into the rhel8-base blueprint from this repo with your own public SSH key
ssh-keygen
vi c_vm/rhel8-base.toml
- Set SELinux to permissive
setenforce 0
- Copy the edited blueprint into the blueprint folder on your server, publish it and ensure it's published
cp c_vm/rhel8-base.toml /var/lib/lorax/composer/blueprints/
composer-cli blueprints push rhel8-base.toml
composer-cli blueprints list|grep rhel8-base
- Start a build with your new blueprint
composer-cli compose start rhel8-base qcow2
- Verify the build and when completed, download the disk image
composer-cli compose status
composer-cli compose image UUID-OF-BUILD
-
Copy the disk image to the server you are deploying the VM from.
-
Copy c_vm, provision_vm.yaml and template-vm.xml to the server you are deploying from and ensure you have ansible installed.
dnf install python-pip
pip install ansible
-
Edit c_vm to reflect on where you have your image file, provision_vm.yaml and your template-vm.xml files.
-
Run c_vm
sudo c_vm name-of-vm
- Done