csmart / ansible-role-virt-infra

Define and manage guests and networks on a KVM host with Ansible
GNU General Public License v3.0
67 stars 48 forks source link

Add ability to run shell commands in guest disk #29

Closed csmart closed 4 years ago

csmart commented 4 years ago

It might be useful to run commands on the boot disk of a guest before it is launched. For example, to set a local mirror, or set a proxy, etc.

This is run as a part of the disk-create.yaml task, after the disk is created and before cloud-init and qemu-guest-agent are installed.

Simply create a list of shell commands that you want to be run against a machine, through the virt_infra_disk_cmd variable.

For example, to set the mirror to use on a Fedora box:

virt_infra_disk_cmd:

Just make sure that it is valid shell commands and it will get run on the disk as root. Note that the VM will have host networking and should be able to get out to network to access the Internet if required.