в файле playbook / vm.yml:
- hosts: all
roles:
- { role: vmdeletion, tags: ['vmdeletion'], when: remove_vm }
- { role: vmcreation, tags: ['vmcreation'] }
- { role: vmpower, tags: ['vmpower'], power: "poweredon" }
в файлах ролей / vmcreation / tasks / main.yml:
- name: Create a virtual machine on given ESXi hostname
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: /DC1/vm/
name: test_vm_0001
state: present
guest_id: centos64Guest
# This is hostname of particular ESXi server on which user wants VM to be deployed
esxi_hostname: "{{ esxi_hostname }}"
disk:
- size_gb: 10
type: thin
datastore: datastore1
hardware:
memory_mb: 512
num_cpus: 4
scsi: paravirtual
networks:
- name: VM Network
mac: aa:bb:dd:aa:00:14
ip: 10.10.10.100
netmask: 255.255.255.0
device_type: vmxnet3
wait_for_ip_address: yes
delegate_to: localhost
register: deploy_vm
, затем выполните:
ansible-playbook playbook/vm.yml -l ${my_groups_or_hosts_limit}
но попробуйте поместить все свои переменные в инвентарь, связанный с вашими хостами / группами, чтобы ваша роль выглядела следующим образом:
в ролях файлов / vmcreation / tasks / main.yml:
- name: Create a virtual machine on given ESXi hostname
vmware_guest:
hostname: "{{ vcenter_hostname }}"
username: "{{ vcenter_username }}"
password: "{{ vcenter_password }}"
validate_certs: no
folder: "{{ vm_folder }}"
name: "{{ inventory_hostname }}"
state: present
guest_id: centos64Guest
# This is hostname of particular ESXi server on which user wants VM to be deployed
esxi_hostname: "{{ vm_esxi_hostname }}"
disk: "{{ vm_disks }}"
hardware: "{{ vm_hardware }}"
networks: "{{ vm_networks }}"
wait_for_ip_address: yes
delegate_to: localhost
register: deploy_vm