Friday, November 17, 2017

To have unique machine id in multiple VMs - Centos

When you clone a VM, sometimes VM id may not be unique and you end up with same VM id for multiple machines.

So, if that is the case just remove /etc/machine-id and then reboot

Then, run systemd-machine-id-setup.

Now, you will have a unique id in /etc/machine-id.   Now, Live happily ever after :) :) 

# systemd-machine-id-setup
Initializing machine ID from KVM UUID.

# cat /etc/machine-id 

Original error faced while using ansible:

failed: [centosmaster] (item=tmaster) => {
    "assertion": "ansible_hostname == hostvars[item]['ansible_hostname'] or ansible_machine_id != hostvars[item]['ansible_machine_id']", 
    "changed": false, 
    "evaluated_to": false, 
    "failed": true, 
    "item": "tmaster"

Monday, November 13, 2017

vagrant - unable to reach host - fix

I was trying to reach a url from inside a vagrant based virtual machine..but unable to reach the same.

It errors out like:

Name or service not known

Tried multiple options - and ended up restarting libvirtd service at host did the trick.

So, sudo systemctl restart libvirtd 

Underlying libvirtd, dnsmasq is running (at host) and I think it is causing some issue.

So, next time, just restart libvirtd and check :)

Monday, November 6, 2017

checkout a github Pull Request locally

So, you have cloned a repo and working on it.

You have a Pull Request(PR) in *upstream* repo which you wish to clone locally.

So, you do the below:

$ git fetch upstream pull/195/head:my_testing

remote: Counting objects: 32, done.
remote: Total 32 (delta 8), reused 8 (delta 8), pack-reused 24
Unpacking objects: 100% (32/32), done.
 * [new ref]         refs/pull/195/head -> my_testing

upstream -> branch from which you actually forked.
195 -> PR number
my_testing -> new branch name

$ git checkout my_testing
Switched to branch 'my_testing'

PS: If you have not forked but cloned the original repo itself, use "origin" instead of "upstream".
Use git config -l  to  see origin, upstream branches.

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.