1.. _vmware_rest_vm_hardware_tuning:
2
3*******************************
4How to modify a virtual machine
5*******************************
6
7.. contents::
8  :local:
9
10
11Introduction
12============
13
14This section shows you how to use Ansible to modify an existing virtual machine.
15
16Scenario requirements
17=====================
18
19You've already followed :ref:`vmware_rest_create_vm` and created a VM.
20
21How to add a CDROM drive to a virtual machine
22=============================================
23
24In this example, we use the ``vcenter_vm_hardware_*`` modules to add a new CDROM to an existing VM.
25
26Add a new SATA adapter
27______________________
28
29First we create a new SATA adapter. We specify the ``pci_slot_number``. This way if we run the task again it won't do anything if there is already an adapter there.
30
31.. literalinclude:: task_outputs/Create_a_SATA_adapter_at_PCI_slot_34.task.yaml
32
33Result
34______
35
36.. literalinclude:: task_outputs/Create_a_SATA_adapter_at_PCI_slot_34.result.json
37
38Add a CDROM drive
39_________________
40
41Now we can create the CDROM drive:
42
43.. literalinclude:: task_outputs/Attach_an_ISO_image_to_a_guest_VM.task.yaml
44
45Result
46______
47
48.. literalinclude:: task_outputs/Attach_an_ISO_image_to_a_guest_VM.result.json
49
50
51.. _vmware_rest_attach_a_network:
52
53How to attach a VM to a network
54===============================
55
56Attach a new NIC
57________________
58
59Here we attach the VM to the network (through the portgroup). We specify a ``pci_slot_number`` for the same reason.
60
61The second task adjusts the NIC configuration.
62
63.. literalinclude:: task_outputs/Attach_a_VM_to_a_dvswitch.task.yaml
64
65Result
66______
67
68.. literalinclude:: task_outputs/Attach_a_VM_to_a_dvswitch.result.json
69
70Adjust the configuration of the NIC
71___________________________________
72
73.. literalinclude:: task_outputs/Turn_the_NIC's_start_connected_flag_on.task.yaml
74
75Result
76______
77
78.. literalinclude:: task_outputs/Turn_the_NIC's_start_connected_flag_on.result.json
79
80Increase the memory of the VM
81=============================
82
83We can also adjust the amount of memory that we dedicate to our VM.
84
85.. literalinclude:: task_outputs/Increase_the_memory_of_a_VM.task.yaml
86
87Result
88______
89
90.. literalinclude:: task_outputs/Increase_the_memory_of_a_VM.result.json
91
92Upgrade the hardware version of the VM
93======================================
94
95Here we use the ``vcenter_vm_hardware`` module to upgrade the version of the hardware:
96
97.. literalinclude:: task_outputs/Upgrade_the_VM_hardware_version.task.yaml
98
99Result
100______
101
102.. literalinclude:: task_outputs/Upgrade_the_VM_hardware_version.result.json
103
104Adjust the number of CPUs of the VM
105===================================
106
107You can use ``vcenter_vm_hardware_cpu`` for that:
108
109.. literalinclude:: task_outputs/Dedicate_one_core_to_the_VM.task.yaml
110
111Result
112______
113
114.. literalinclude:: task_outputs/Dedicate_one_core_to_the_VM.result.json
115
116Remove a SATA controller
117========================
118
119In this example, we remove the SATA controller of the PCI slot 34.
120
121.. literalinclude:: task_outputs/Remove_SATA_adapter_at_PCI_slot_34.result.json
122
123Result
124______
125
126.. literalinclude:: task_outputs/Remove_SATA_adapter_at_PCI_slot_34.result.json
127
128Attach a floppy drive
129=====================
130
131Here we attach a floppy drive to a VM.
132
133.. literalinclude:: task_outputs/Add_a_floppy_disk_drive.task.yaml
134
135Result
136______
137
138.. literalinclude:: task_outputs/Add_a_floppy_disk_drive.result.json
139
140Attach a new disk
141=================
142
143Here we attach a tiny disk to the VM. The ``capacity`` is in bytes.
144
145.. literalinclude:: task_outputs/Create_a_new_disk.task.yaml
146
147Result
148______
149
150.. literalinclude:: task_outputs/Create_a_new_disk.result.json
151