-
Notifications
You must be signed in to change notification settings - Fork 0
/
increase_node_cpus.yml
54 lines (46 loc) · 1.68 KB
/
increase_node_cpus.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
---
- name: Increase node CPUs
hosts: localhost
connection: local
gather_facts: false
# These variables are intended to be overriden using the `--extra-vars`
# command line option:
vars:
# Maximum number of CPUs to assing to the VM.
max_cpus: 4
# Amount of CPUs to add in each increase.
inc_cpus: 1
tasks:
# Calculate the IP address from the `instance` input variable, and then do a
# reverse DNS lookup to find the FQDN, which in this environment is equal to
# the name of the virtual machine.
- set_fact:
vm_ip: "{{ instance | regex_replace(':.*$') }}"
- set_fact:
vm_name: "{{ lookup('dig', vm_ip + '/PTR') | regex_replace('\\.$') }}"
# Retrieve the facts of the virtual machine, so that we can check that it
# exists and get its current amount of CPUs:
- ovirt_vms_facts:
pattern: "name={{ vm_name }}"
- debug:
var: ovirt_vms
# Fail if the virtual machine doesn't exist:
- fail:
msg: "Virtual machine '{{ vm_name }}' doesn't exist"
when: ovirt_vms | length == 0
# Extract the current number of CPUs. Note that we get and increase the number
# os sockets, not the number of cores per socket, because that is what can be
# changed without restarting the virtual machine in oVirt.
- set_fact:
current_cpus: "{{ ovirt_vms[0].cpu.topology.sockets }}"
var: current_cpus
# Calculate the new number of CPUs:
- set_fact:
new_cpus: "{{ [current_cpus|int + inc_cpus|int, max_cpus|int] | min }}"
- debug:
var: new_cpus
# Update the virtual machine with the new number of CPUs:
- ovirt_vms:
name: "{{ vm_name }}"
cpu_sockets: "{{ new_cpus }}"
when: new_cpus > current_cpus