티스토리 뷰

DevOps/System&Tools

ansible with vmware

Jacob_baek 2017. 7. 28. 13:39


vmware_guest module을 사용하기전 아래 python package를 설치해야 한다.


TASK [deploy] ****************************************************************************************************************************

fatal: [localhost -> localhost]: FAILED! => {"changed": false, "failed": true, "msg": "pyvmomi module required"}

        to retry, use: --limit @/root/ansible-examples/vsphere_guest/site.retry


만약 pyvmomi가 존재하지 않을 경우 아래와 같이 pyvmomi 설치를 진행한다.

[root@atestsrv vsphere_guest]# pip install pyvmomi

Collecting pyvmomi

  Downloading pyvmomi-6.5.0.2017.5-1.tar.gz (252kB)

    100% |████████████████████████████████| 256kB 1.3MB/s

Collecting requests>=2.3.0 (from pyvmomi)

  Downloading requests-2.18.4-py2.py3-none-any.whl (88kB)

    100% |████████████████████████████████| 92kB 4.7MB/s




vmware_guest 


다음 모듈을 가지고 있고 지원한다.

[root@atestsrv vsphere_guest]# ansible-doc -l | grep vmware

vmware_cluster                            Manage VMware vSphere clusters

vmware_datacenter                         Manage VMware vSphere Datacenters

vmware_dns_config                         Manage VMware ESXi DNS Configuration

vmware_dvs_host                           Add or remove a host from distributed virtual switch

vmware_dvs_portgroup                      Create or remove a Distributed vSwitch portgroup

vmware_dvswitch                           Create or remove a distributed vSwitch

vmware_guest                              Manages virtual machines in vCenter

vmware_guest_facts                        Gather facts about a single VM

vmware_guest_find                         Find the folder path(s) for a VM by name or UUID

vmware_guest_snapshot                     Manages virtual machines snapshots in vcenter

vmware_guest_tools_wait                   Wait for VMware tools to become available

vmware_host                               Add/remove ESXi host to/from vCenter

vmware_local_user_manager                 Manage local users on an ESXi host

vmware_maintenancemode                    Place a host into maintenance mode

vmware_migrate_vmk                        Migrate a VMK interface from VSS to VDS

vmware_portgroup                          Create a VMware portgroup

vmware_resource_pool                      Add/remove resource pools to/from vCenter

vmware_target_canonical_facts             Return canonical (NAA) from an ESXi host

vmware_vm_facts                           Return basic facts pertaining to a vSphere virtual machine guest

vmware_vm_shell                           Execute a process in VM

vmware_vm_vss_dvs_migrate                 Migrates a virtual machine from a standard vswitch to distributed

vmware_vmkernel                           Create a VMware VMkernel Interface

vmware_vmkernel_ip_config                 Configure the VMkernel IP Address

vmware_vmotion                            Move a virtual machine using vMotion

vmware_vsan_cluster                       Configure VSAN clustering on an ESXi host

vmware_vswitch                            Add or remove a VMware Standard Switch to an ESXi host



아래와 같은 샘플코드를 사용하면 vsphere에 VM을 생성하고 전원을 on할 수 있다.

sample code


---

- name: deploy guest vm on vsphere

  hosts: localhost

  gather_facts: no

  tasks:

  - name: deploy

    vmware_guest:

      hostname: vCenter_ip_or_domain_name

      username: administrator@vsphere.local

      password: password

      validate_certs: no

      datacenter: Datacenter_Name

      # cluster: Cluster_name 

      # esxi_hostname과 동시에 사용할 수 없다.

      esxi_hostname: 192.168.6.195

      folder: /testvms

      name: testvm_by_ansible

      state: poweredon

      template: CentOS7

      disk:

      - size_gb: 50

        type: thin

        #autoselect_datastore: yes

        datastore: container_datastore

      hardware:

        memory_mb: 2048

        num_cpus: 2

        scsi: paravirtual

#      wait_for_ip_address: yes

      networks:

      - name: vss_name

        ip: 192.168.1.100

        netmask: 255.255.255.0

        gateway: 192.168.1.1

        dns_server:

        - 8.8.8.8

        - 8.8.4.4

    delegate_to: localhost

    register: deploy



이전 모듈인 vsphere_guest는 아래 링크를 참고한다.

vsphere_guest는 pysphere의 의존성을 가진다.

- http://everythingshouldbevirtual.com/creating-vsphere-vms-using-ansible

- http://docs.ansible.com/ansible/latest/vsphere_guest_module.html


참고로 vcenter deploy ansible template도 있다.

- https://github.com/vmware/ansible-role-vcenter

'DevOps > System&Tools' 카테고리의 다른 글

nexus  (0) 2019.11.12
k3s integrated with GitLab  (0) 2019.10.03
dynamic inventory  (0) 2018.07.24
ansible cisco  (0) 2017.09.28
ansible with openstack  (0) 2017.07.28
ansible with vmware  (0) 2017.07.28
댓글
댓글쓰기 폼