728x90
728x90
# vi vm.yml
---
- hosts: localhost
vars:
ansible_python_interpreter: /bin/python3
gather_facts: no
vcenter_hostname: "172.16.10.104"
vcenter_username: "administrator@team4.local"
vcenter_password: "VMware1!"
datacenter_name: "Datacenter"
esxi_hostname: "172.16.10.14"
project_id: "khb-00"
public_net: "External"
private_net: "{{ project_id + '-Openshift' }}"
folder_prefix: "/Datacenter/vm/1.Projects/"
datastore_name: "RECA4-04"
iso_folder: '[RECA4-04]\ISO\'
tasks:
- name: 06. Create Project VMs t
community.vmware.vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: 'false'
datacenter: '{{datacenter_name}}'
folder: '{{ folder_prefix + project_id }}'
name: "{{ project_id + item.vmname }}"
esxi_hostname: "{{ esxi_hostname }}"
datastore: '{{ datastore_name }}'
guest_id: '{{ item.guest_id }}'
hardware:
num_cpus: '{{ item.cpus }}'
memory_mb: '{{ item.memory }}'
scsi: paravirtual
disk:
- size_gb: '{{ item.disk_gb }}'
type: thin
networks:
- name: '{{ private_net }}'
device_type: vmxnet3
cdrom:
- controller_number: 0
unit_number: 0
state: present
type: iso
iso_path: '{{ iso_folder + item.iso }}'
state: poweredoff
loop:
- { vmname: -Bastion, guest_id: centos8_64Guest, cpus: 4, memory: 16384, disk_gb: 120, iso: 'CentOS-Stream-8-20231106.0-x86_64-dvd1.iso' }
- { vmname: -Bootstrap, guest_id: rhel8_64Guest, cpus: 4, memory: 16384, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Master-01, guest_id: rhel8_64Guest, cpus: 4, memory: 16384, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Master-02, guest_id: rhel8_64Guest, cpus: 4, memory: 16384, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Master-03, guest_id: rhel8_64Guest, cpus: 4, memory: 16384, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Woker-01, guest_id: rhel8_64Guest, cpus: 2, memory: 8192, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Woker-02, guest_id: rhel8_64Guest, cpus: 2, memory: 8192, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
- { vmname: -Woker-03, guest_id: rhel8_64Guest, cpus: 2, memory: 8192, disk_gb: 120, iso: 'rhcos-live.x86_64.iso' }
delegate_to: localhost
register: deploy_vm
# ansible-playbook vm.yml
728x90