ansible galaxy govc centos 7 mark vm as template , create clone form template template folder

root@controller roles]# pwd
/etc/ansible/roles
[root@controller roles]#

vmware.govc

[root@controller ~]# cat vmware.yaml

- hosts: localhost
  roles:
    - role: vmware.govc

[root@controller ~]#
[root@controller ~]# ansible-playbook vmware.yaml

PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [vmware.govc : Check the current govc version (if any)] *******************
fatal: [localhost]: FAILED! => {"changed": false, "cmd": "/usr/bin/govc version", "msg": "[Errno 2] No such file or directory", "rc": 2}
...ignoring

TASK [vmware.govc : Download archive 32 bits] **********************************
skipping: [localhost]

TASK [vmware.govc : Download archive 64 bits] **********************************
changed: [localhost]

TASK [vmware.govc : Uncompress govc binary] ************************************
changed: [localhost]

TASK [vmware.govc : move govc into place] **************************************
changed: [localhost]

TASK [vmware.govc : Ensure govc executable] ************************************
changed: [localhost]

TASK [vmware.govc : Verify installed govc version] *****************************
ok: [localhost]

TASK [vmware.govc : Assert correct installed version] **************************
ok: [localhost] => {
    "changed": false,
    "msg": "All assertions passed"
}

TASK [vmware.govc : Check for existing VM] *************************************

TASK [vmware.govc : debug] *****************************************************
skipping: [localhost]

TASK [vmware.govc : Import OVA] ************************************************

TASK [vmware.govc : debug] *****************************************************
skipping: [localhost]

TASK [vmware.govc : On Import Failed] ******************************************

TASK [vmware.govc : Push cloud init seed to vcenter datastore] *****************
skipping: [localhost]

TASK [vmware.govc : Insert cloud-init cdrom into vm] ***************************
skipping: [localhost]

TASK [vmware.govc : Mount the cloud-init cdrom on the vm] **********************
skipping: [localhost]

TASK [vmware.govc : Power on vm] ***********************************************
skipping: [localhost]

TASK [vmware.govc : Wait for vm boot] ******************************************
skipping: [localhost]

PLAY RECAP *********************************************************************
localhost                  : ok=8    changed=4    unreachable=0    failed=0 


 export GOVC_URL=192.168.0.108
 export GOVC_USERNAME=root
 export GOVC_PASSWORD=vmware
export GOVC_INSECURE=true
[root@controller roles]# govc about
Name:         VMware ESXi
Vendor:       VMware, Inc.
Version:      5.5.0
Build:        2068190
OS type:      vmnix-x86
API type:     HostAgent
API version:  5.5
Product ID:   embeddedEsx
UUID:       

[root@controller ~]# govc datacenter.info
Name:                ha-datacenter
  Path:              /ha-datacenter
  Hosts:             1
  Clusters:          0
  Virtual Machines:  6
  Networks:          1
  Datastores:        1


[root@controller ~]# govc ls
/ha-datacenter/vm
/ha-datacenter/network
/ha-datacenter/host
/ha-datacenter/datastore


[root@controller ~]# govc vm.info ans-*
Name:           ans-nginx01
  Path:         /ha-datacenter/vm/ans-nginx01
  UUID:         42137010-0489-3a76-a4d7-78de34cfc8ca
  Guest name:   Red Hat Enterprise Linux 6 (32-bit)
  Memory:       256MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:   
  Host:         localhost.localdomain
Name:           ans-db01
  Path:         /ha-datacenter/vm/ans-db01
  UUID:         421333cc-5a15-9248-c0f4-852a1099878b
  Guest name:   Red Hat Enterprise Linux 6 (32-bit)
  Memory:       248MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:   
  Host:         localhost.localdomain
Name:           ans-db02
  Path:         /ha-datacenter/vm/ans-db02
  UUID:         421321d8-e1ea-394c-1bb5-bb29fc4c7034
  Guest name:   Red Hat Enterprise Linux 6 (32-bit)
  Memory:       1128MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:   
  Host:         localhost.localdomain
Name:           ans-nginx02
  Path:         /ha-datacenter/vm/ans-nginx02
  UUID:         42136f70-914b-4f1f-056f-a063e24519af
  Guest name:   Red Hat Enterprise Linux 6 (32-bit)
  Memory:       256MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:   
  Host:         localhost.localdomain
[root@controller ~]# 

[root@controller ~]# govc vm.info ans-db01
Name:           ans-db01
  Path:         /ha-datacenter/vm/ans-db01
  UUID:         421333cc-5a15-9248-c0f4-852a1099878b
  Guest name:   Red Hat Enterprise Linux 6 (32-bit)
  Memory:       248MB
  CPU:          1 vCPU(s)
  Power state:  poweredOff
  Boot time:    <nil>
  IP address:   
  Host:         localhost.localdomain
[root@controller ~]# 


[root@controller ~]#  govc datastore.info
Name:        datastore1
  Path:      /ha-datacenter/datastore/datastore1
  Type:      VMFS
  URL:       /vmfs/volumes/5d67343f-9e0e3e8d-89e9-000c297966bc
  Capacity:  32.5 GB
  Free:      17.9 GB
[root@controller ~]# 



[root@ansible ~]# govc about
Name:         VMware vCenter Server
Vendor:       VMware, Inc.
Version:      5.5.0
Build:        2183111
OS type:      linux-x64
API type:     VirtualCenter
API version:  5.5
Product ID:   vpx
UUID:         2988B9DB-62CE-4FAE-8148-D93C2CC6B04E
[root@ansible ~]# 

[root@ansible ~]# govc datastore.info -dc="dc" -k=true datastore1
Name:        datastore1
  Path:      /dc/datastore/datastore1
  Type:      VMFS
  URL:       ds:///vmfs/volumes/5d67343f-9e0e3e8d-89e9-000c297966bc/
  Capacity:  32.5 GB
  Free:      15.8 GB

mark a running vm ans-db01 to template

[root@ansible ~]# govc vm.markastemplate ans-db01

clone a vm from template ans-db01
[root@ansible ~]# govc vm.clone -vm ans-db01 new-vm
[11-10-19 09:42:31] Cloning /dc/vm/Discovered virtual machine/ans-db01 to new-vm...OK

[root@ansible ~]#  govc vm.clone -vm ans-db01  new-vm1
[11-10-19 09:52:58] Cloning /dc/vm/Discovered virtual machine/ans-db01 to new-vm1...OK

clone a vm from other vm on vcenter

root@localhost ~]#  govc vm.clone -vm ans-db02 db01
[13-10-19 13:37:38] Cloning /dc/vm/ans-db02 to db01...ok

root@localhost ~]#  govc vm.clone -vm ans-db02 db03
[13-10-19 17:23:15] Cloning /dc/vm/ans-db02 to db03...OK

Comments