Guest User

Untitled

a guest
Jan 17th, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -x
  4.  
  5. # array of virtual machines
  6. virtmach=(ose37)
  7.  
  8. rhusername="username"
  9. rhpassword="password"
  10. rootpass="password"
  11. poolid="poolid"
  12.  
  13. for vm in ${virtmach[@]}
  14. do
  15. cp /instances/images/rhel74.qcow2 /instances/$vm.qcow2
  16. qemu-img resize /instances/$vm.qcow2 +32G
  17. cp /instances/${vm}.qcow2 /instances/${vm}-orig.qcow2
  18.  
  19. virt-resize --quiet --expand /dev/vda1 /instances/${vm}-orig.qcow2 /instances/${vm}.qcow2
  20. rm /instances/${vm}-orig.qcow2
  21.  
  22. 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
  23. sleep 60
  24. virsh shutdown $vm
  25. sleep 30
  26. 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
  27. virsh start $vm
  28. sleep 90
  29. ip=`virsh qemu-agent-command $vm '{"execute":"guest-network-get-interfaces"}' | jq '.return[1]["ip-addresses"][0]["ip-address"]'`
  30.  
  31.  
  32. temp="${ip%\"}"
  33. temp="${temp#\"}"
  34.  
  35.  
  36. echo "$vm ansible_host=$temp" >> hosts.ini
  37. done
Add Comment
Please, Sign In to add comment