Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- set -x
- # array of virtual machines
- virtmach=(ose37)
- rhusername="username"
- rhpassword="password"
- rootpass="password"
- poolid="poolid"
- for vm in ${virtmach[@]}
- do
- cp /instances/images/rhel74.qcow2 /instances/$vm.qcow2
- qemu-img resize /instances/$vm.qcow2 +32G
- cp /instances/${vm}.qcow2 /instances/${vm}-orig.qcow2
- virt-resize --quiet --expand /dev/vda1 /instances/${vm}-orig.qcow2 /instances/${vm}.qcow2
- rm /instances/${vm}-orig.qcow2
- virt-install --import --name $vm --memory 8192 --vcpus 2 --disk path=/instances/$vm.qcow2,format=qcow2,bus=virtio --network network=ovsbr0,portgroup=vlan-250 --graphics none --console pty,target_type=serial --os-type linux --os-variant rhel7.0 --noautoconsole
- sleep 60
- virsh shutdown $vm
- sleep 30
- virt-sysprep -d $vm --firstboot-command 'yum erase -y cloud-init;subscription-manager repos --disable="*";subscription-manager repos --enable="rhel-7-server-rpms" --enable="rhel-7-server-extras-rpms";yum install -y wget git net-tools bind-utils iptables-services bridge-utils bash-completion kexec-tools sos psacct;yum update -y' --hostname $vm.virtomation.com --root-password password:${rootpass} --sm-register --sm-credentials '${rhusername}':password:'${rhpassword}' --sm-attach pool:${poolid} --network
- virsh start $vm
- sleep 90
- ip=`virsh qemu-agent-command $vm '{"execute":"guest-network-get-interfaces"}' | jq '.return[1]["ip-addresses"][0]["ip-address"]'`
- temp="${ip%\"}"
- temp="${temp#\"}"
- echo "$vm ansible_host=$temp" >> hosts.ini
- done
Add Comment
Please, Sign In to add comment