{"id":15655230,"url":"https://github.com/jtyr/ansible-vmware_vm_provisioning","last_synced_at":"2025-05-04T08:38:12.319Z","repository":{"id":69603821,"uuid":"142048611","full_name":"jtyr/ansible-vmware_vm_provisioning","owner":"jtyr","description":"Ansible role which helps to provision VMs on VMware vCenter.","archived":false,"fork":false,"pushed_at":"2023-02-09T19:25:03.000Z","size":65,"stargazers_count":29,"open_issues_count":1,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-03-30T21:33:24.478Z","etag":null,"topics":["ansible","ansible-role","vcenter","vm","vmware","vmware-vsphere"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jtyr.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-07-23T17:44:59.000Z","updated_at":"2024-11-19T06:37:31.000Z","dependencies_parsed_at":null,"dependency_job_id":"fcd86375-0c81-460c-a980-1d2f48e8148e","html_url":"https://github.com/jtyr/ansible-vmware_vm_provisioning","commit_stats":null,"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-vmware_vm_provisioning","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-vmware_vm_provisioning/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-vmware_vm_provisioning/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jtyr%2Fansible-vmware_vm_provisioning/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jtyr","download_url":"https://codeload.github.com/jtyr/ansible-vmware_vm_provisioning/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252136905,"owners_count":21700097,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ansible","ansible-role","vcenter","vm","vmware","vmware-vsphere"],"created_at":"2024-10-03T12:57:13.377Z","updated_at":"2025-05-03T03:20:49.069Z","avatar_url":"https://github.com/jtyr.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"vmware_vm_provisioning\n======================\n\nAnsible role which helps to provision VMs on VMware vCenter.\n\nThe configuration of the role is done in such way that it should not be\nnecessary to change the role for any kind of configuration. All can be\ndone either by changing role parameters or by declaring completely new\nconfiguration as a variable. That makes this role absolutely\nuniversal. See the examples below for more details.\n\nPlease report any issues or send PR.\n\n\nExamples\n--------\n\n```yaml\n---\n\n- name: Example of how to provision VMs (all in one data structure)\n  hosts: all\n  connection: local\n  gather_facts: no\n  vars:\n    # List of VMs to provision\n    vmware_vm_provisioning_vms:\n      # Fist VM\n      - name: test01\n        hostname: vcenter.example.com\n        username: administrator@example.com\n        password: p4ssw0rd\n        validate_certs: no\n        datacenter: DC1\n        cluster: Cluster1\n        folder: /DC1/vm\n        template: CentOS-7-1525432016\n        disks:\n          - size_gb: 20\n            autoselect_datastore: yes\n        network:\n          - name: VM Network\n            ip: 192.168.1.178\n            netmask: 255.255.255.0\n            gateway: 192.168.1.1\n        hadrware:\n          num_cpus: 2\n          memory_mb: 2048\n\n      # Second VM\n      - name: test02\n        hostname: vcenter.example.com\n        username: administrator@example.com\n        password: p4ssw0rd\n        validate_certs: no\n        datacenter: DC2\n        cluster: Cluster2\n        folder: /DC2/vm\n        template: CentOS-7-1525432016\n        disks:\n          - size_gb: 20\n            autoselect_datastore: yes\n          - size_gb: 500\n            type: thin\n            autoselect_datastore: yes\n        network:\n          - name: VM Network\n            ip: 10.0.0.178\n            netmask: 255.255.255.0\n            gateway: 10.0.0.1\n        hadrware:\n          num_cpus: 2\n          memory_mb: 16384\n          nested_virt: yes\n        # This will power off the VM in order to be able to set newly set\n        # properties (e.g. increased RAM, CPUs, ...)\n        state: changed\n\n      # Third VM\n      - name: test03\n        hostname: vcenter.example.com\n        username: administrator@example.com\n        password: p4ssw0rd\n        validate_certs: no\n        datacenter: DC2\n        cluster: Cluster2\n        folder: /DC2/vm\n        disks:\n          - size_gb: 20\n            autoselect_datastore: yes\n          - size_gb: 500\n            type: thin\n            autoselect_datastore: yes\n        network:\n          - name: VM Network\n            ip: 10.0.0.179\n            netmask: 255.255.255.0\n            gateway: 10.0.0.1\n        hadrware:\n          num_cpus: 2\n          memory_mb: 16384\n          nested_virt: yes\n        # Keep the MAC address from the original VM even after the rebuild\n        # {macAddress}\n        #    - filters out devices which have macAddress key\n        # {macAddress==aa:bb:cc:dd:ee:ff}\n        #    - filters out devices which have macAddress value rqual to that address\n        # {macAddress=~aa:bb:cc:dd:ee:f[0-9]}\n        #    - filters out devices which have macAddress value matching the regexp\n        add_facts:\n          - src: config.hardware.device.{macAddress}.0.macAddress\n            dest: networks.0.mac\n        # Special state implemented only by this role\n        # It will power off, remove and create the VM\n        state: rebuilt\n  roles:\n    - role: vmware_vm_provisioning\n      tags: vmware_vm_provisioning\n      when: \u003e\n        inventory_hostname == 'localhost'\n\n- name: The same like above but with reusable variables\n  hosts: all\n  connection: local\n  gather_facts: no\n  vars:\n    # Default login details\n    vmware_vm_provisioning_hostname: vcenter.example.com\n    vmware_vm_provisioning_username: administrator@example.com\n    vmware_vm_provisioning_password: p4ssw0rd\n    vmware_vm_provisioning_validate_certs: no\n\n    # Default template\n    vmware_vm_provisioning_template: CentOS-7-1525432016\n\n    # Default HW configuration\n    vmware_vm_provisioning_hardware: \u0026vmware_vm_provisioning_hardware\n      num_cpus: 2\n      memory_mb: 2048\n\n    # Disk configuration (size corresponds with the disk size from the template)\n    vmware_vm_provisioning_disk__image: \u0026vmware_vm_provisioning_disk__image\n      size_gb: 5\n      autoselect_datastore: yes\n\n    # Default list of disks\n    vmware_vm_provisioning_disk:\n      - \"{{ vmware_vm_provisioning_disk__image }}\"\n\n    # Network configuration for MyNET1\n    vmware_vm_provisioning_networks__mynet1: \u0026vmware_vm_provisioning_networks__mynet1\n      - name: VM Network\n        netmask: 255.255.255.0\n        gateway: 192.168.1.1\n\n    # Network configuration for MyNET1\n    vmware_vm_provisioning_networks__mynet1: \u0026vmware_vm_provisioning_networks__mynet2\n      - name: VM Network\n        netmask: 255.255.255.0\n        gateway: 10.0.0.1\n\n    # DC1 - Cluster1\n    vmware_vm_provisioning__dc1_cluster1: \u0026vmware_vm_provisioning__dc1_cluster1\n      datacenter: DC1\n      cluster: Cluster1\n      folder: /DC1/vm\n\n    # DC2 - Cluster2\n    vmware_vm_provisioning__dc2_cluster2: \u0026vmware_vm_provisioning__dc2_cluster2\n      datacenter: DC2\n      cluster: Cluster2\n      folder: /DC2/vm\n\n    # List of VMs to provision\n    vmware_vm_provisioning_vms:\n      # First VM\n      - \u003c\u003c: *vmware_vm_provisioning__dc1_cluster1\n        name: test01\n        networks:\n          # Include the default network configuration\n          - \u003c\u003c: *vmware_vm_provisioning_networks__mynet1\n            # And jsut add the IP\n            ip: 192.168.1.178\n\n      # Second VM\n      - \u003c\u003c: *vmware_vm_provisioning__dc2_cluster2\n        name: test02\n        networks:\n          # Include the default network configuration\n          - \u003c\u003c: *vmware_vm_provisioning_networks__mynet2\n            # And jsut add the IP\n            ip: 10.0.0.178\n        disks:\n          # Include the default disk configuration\n          - \u003c\u003c: *vmware_vm_provisioning_disk__image\n          # Add one more disk (500G)\n          - size_gb: 500\n            type: thin\n            # Detach disk before rebuilding the VM\n            _userdata: yes\n            autoselect_datastore: yes\n        hardware:\n          # Include the default hardware settings\n          \u003c\u003c: *vmware_vm_provisioning_hardware\n          # And override memory size\n          memory_mb: 16384\n          # And add one more additional option\n          nested_virt: yes\n\n      # Third VM\n      - \u003c\u003c: *vmware_vm_provisioning__dc2_cluster2\n        name: test03\n        networks:\n          # Different way of setting the IP\n          - \"{{ vmware_vm_provisioning_networks__mynet2 | combine({ 'ip': '10.0.0.179' }) }}\"\n        # Different way of adding an extra disk\n        disks: \"{{\n          vmware_vm_provisioning_disk +\n          [{ 'size_gb': 500,\n             'type': 'thin',\n             '_userdata': true,\n             'autoselect_datastore': true }] }}\"\n        # Different way of setting the HW params\n        hardware: \"{{\n          vmware_vm_provisioning_hardware | combine({\n            'memory_mb': 16384,\n            'nested_virt': true }) }}\"\n        # Keep the MAC address from the original VM even after the rebuild\n        # {macAddress}\n        #    - filters out devices which have macAddress key\n        # {macAddress==aa:bb:cc:dd:ee:ff}\n        #    - filters out devices which have macAddress value rqual to that address\n        # {macAddress=~aa:bb:cc:dd:ee:f[0-9]}\n        #    - filters out devices which have macAddress value matching the regexp\n        add_facts:\n          - src: config.hardware.device.{macAddress}.0.macAddress\n            dest: networks.0.mac\n        # Special state implemented only by this role\n        # It will power off, remove and create the VM\n        state: rebuilt\n  roles:\n    - role: vmware_vm_provisioning\n      tags: vmware_vm_provisioning\n```\n\nIn order to provision only certain VMs, you can use the following approach:\n\n```shell\nansible-playbook \\\n  # Inventory with the VMs we want to provision\n  -i hosts \\\n  # Limit execution only for VMs test01 and test03\n  -l '~test0[13]' \\\n  # The name of the playbook from the examples above\n  vm_provisioning.yaml\n```\n\nWe can also use execute Ansible with multiple playbooks to configure the VM\nright after it was provisioned:\n\n```shell\nansible-playbook \\\n  -i hosts \\\n  -l '~test0[13]' \\\n  vm_provisioning.yaml \\\n  # That's the second playbook which configures the provisioned VM(s)\n  site.yaml\n```\n\nUse `--forks` option to controll how many VMs should be managed in parallel.\n\n\nRole variables\n--------------\n\n```yaml\n# List of VMs to provision (see README for details)\nvmware_vm_provisioning_vms: []\n\n# Default values (see README for details)\n#vmware_vm_provisioning_annotation: null\n#vmware_vm_provisioning_cdrom: null\n#vmware_vm_provisioning_cluster: null\n#vmware_vm_provisioning_customization: null\n#vmware_vm_provisioning_customization_spec: null\n#vmware_vm_provisioning_customvalues: null\n#vmware_vm_provisioning_datacenter: null\n#vmware_vm_provisioning_disks: null\n#vmware_vm_provisioning_esxi_hostname: null\n#vmware_vm_provisioning_folder: null\n#vmware_vm_provisioning_force: null\n#vmware_vm_provisioning_guest_id: null\n#vmware_vm_provisioning_hardware: null\n#vmware_vm_provisioning_hostname: null\n#vmware_vm_provisioning_is_template: null\n#vmware_vm_provisioning_linked_clone: null\n#vmware_vm_provisioning_name_match: null\n#vmware_vm_provisioning_networks: null\n#vmware_vm_provisioning_password: null\n#vmware_vm_provisioning_port: null\n#vmware_vm_provisioning_resource_pool: null\n#vmware_vm_provisioning_snapshot_src: null\n#vmware_vm_provisioning_state_change_timeout: null\n#vmware_vm_provisioning_state: null\n#vmware_vm_provisioning_template: null\n#vmware_vm_provisioning_username: null\n#vmware_vm_provisioning_uuid: null\n#vmware_vm_provisioning_validate_certs: null\n#vmware_vm_provisioning_vapp_properties: null\n#vmware_vm_provisioning_wait_for_ip_address: null\n\n# SCSI controller ID used for the disk detachment\n#vmware_vm_provisioning_scsi_controller: 0\n```\n\n\nLicense\n-------\n\nMIT\n\n\nAuthor\n------\n\nJiri Tyr\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtyr%2Fansible-vmware_vm_provisioning","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjtyr%2Fansible-vmware_vm_provisioning","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjtyr%2Fansible-vmware_vm_provisioning/lists"}