Friday, October 27, 2017

Template creation from a Virtual Machine

Template  creation from a Virtual Machine:

Before creating a template out of a virtual machine, we need to delete unique stuff related to a VM. For example, hostname, mac address, UUID.

You can use the following commands to make it generic enough and then save the template.


hostnamectl set-hostname localhost.localdomain

Remove the entries starting with 'UUID" & "HWADDR" in /etc/sysconfig/network-scripts/ifcfg-eth0 ( on all the interfaces, in case of more than one NIC available ).

Delete all but one file




Delete all but one file:

ls | grep -v testfile.tar | xargs rm 

So, all files except testfile.tar will be deleted.


use "xargs rm -rf"   if you wish to delete directories as well.


vagrant + ansible

vagrant + ansible

I have followed this neat tutorial https://fedoramagazine.org/using-ansible-provision-vagrant-boxes/


After trying out the above, I have tried out provisioning by modifying ansible file.

So, Add the below lines in lamp.yml and then:

# vagrant provision 

lamp.yml
- name: Creates directory
  file: path=/tmp/newdirectory state=directory
The above makes changes in running image and can observed using vagrant ssh
Note, you need to do vagrant ssh in the same directory to verify same. (lampbox in this example).