-
Notifications
You must be signed in to change notification settings - Fork 12
/
vmware_add_disk_to_vm.yml
85 lines (75 loc) · 2.93 KB
/
vmware_add_disk_to_vm.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
---
- name: Add disk to VMware VM
hosts: all
connection: local
gather_facts: false
vars:
- vm_disksize: "1 GB"
- use_inventory_for_hostname: false
tasks:
- name: Get the short hostname from inventory
# Normally there is dot in fqdn, vmware inventory has _ as separator
set_fact:
short_name: "{{ inventory_hostname | regex_search('^[^_.]*') }}"
when: use_inventory_for_hostname
- name: >
Use vmware credentials from vault if set there, otherwise
from AAP credentials
set_fact:
vcenter_credentials:
vcenter_server: '{{ lookup("env", "VMWARE_HOST") }}'
vcenter_username: '{{ lookup("env", "VMWARE_USER") }}'
vcenter_password: '{{ lookup("env", "VMWARE_PASSWORD") }}'
when:
- vcenter_credentials is undefined
- vcenter_credentials.vcenter_server is undefined
- vcenter_credentials.vcenter_username is undefined
- vcenter_credentials.vcenter_password is undefined
- name: >
Use vmware credentials from vault if set there, and not set in params
set_fact:
vcenter_hostname: '{{ vcenter_credentials.vcenter_server }}'
vcenter_username: '{{ vcenter_credentials.vcenter_username }}'
vcenter_password: '{{ vcenter_credentials.vcenter_password }}'
when:
- vcenter_credentials is defined
- vcenter_credentials.vcenter_server is defined
- vcenter_credentials.vcenter_username is defined
- vcenter_credentials.vcenter_password is defined
- vcenter_hostname is undefined
- vcenter_username is undefined
- vcenter_password is undefined
- name: Look up the VM called {{ short_name }} in the inventory
register: search_result
vmware.vmware_rest.vcenter_vm_info:
filter_names:
- "{{ short_name }}"
vcenter_hostname: "{{ vcenter_hostname }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
vcenter_validate_certs: false
- name: Collect information about a specific VM
vmware.vmware_rest.vcenter_vm_info:
vm: "{{ search_result.value[0].vm }}"
vcenter_hostname: "{{ vcenter_hostname }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
vcenter_validate_certs: false
register: vmware_vm_info
- name: Create a new disk to VM
vmware.vmware_rest.vcenter_vm_hardware_disk:
vm: "{{ vmware_vm_info.id }}"
type: SCSI
state: present
new_vmdk:
# e.g. 5GB
capacity: "{{ vm_disksize |human_to_bytes }}"
vcenter_hostname: "{{ vcenter_hostname }}"
vcenter_username: "{{ vcenter_username }}"
vcenter_password: "{{ vcenter_password }}"
vcenter_validate_certs: false
register: my_new_disk
- name: Debug new disk creating
debug:
var: my_new_disk
verbosity: 1