Skip to content

Commit 976392e

Browse files
author
Rodrique Heron
committed
fix merge conflict
2 parents 1d474d4 + 897adbe commit 976392e

File tree

11 files changed

+141
-12
lines changed

11 files changed

+141
-12
lines changed

CHANGELOG.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Changelog
2+
3+
## [qbnv2.4.4](https://github.com/Qubinode/deploy-kvm-vm/tree/qbnv2.4.4) (2021-01-12)
4+
5+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v1.2.0...qbnv2.4.4)
6+
7+
## [v1.2.0](https://github.com/Qubinode/deploy-kvm-vm/tree/v1.2.0) (2021-01-12)
8+
9+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v1.2...v1.2.0)
10+
11+
## [v1.2](https://github.com/Qubinode/deploy-kvm-vm/tree/v1.2) (2020-12-31)
12+
13+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v2.4.2...v1.2)
14+
15+
## [v2.4.2](https://github.com/Qubinode/deploy-kvm-vm/tree/v2.4.2) (2020-07-29)
16+
17+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v2.4.0...v2.4.2)
18+
19+
## [v2.4.0](https://github.com/Qubinode/deploy-kvm-vm/tree/v2.4.0) (2020-05-31)
20+
21+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v1.0.0...v2.4.0)
22+
23+
## [v1.0.0](https://github.com/Qubinode/deploy-kvm-vm/tree/v1.0.0) (2019-12-28)
24+
25+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v1.1...v1.0.0)
26+
27+
**Merged pull requests:**
28+
29+
- removed /dev/sda1, replaced with dynamic variable [\#1](https://github.com/Qubinode/deploy-kvm-vm/pull/1) ([amalivert](https://github.com/amalivert))
30+
31+
## [v1.1](https://github.com/Qubinode/deploy-kvm-vm/tree/v1.1) (2019-11-07)
32+
33+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/v1.0...v1.1)
34+
35+
## [v1.0](https://github.com/Qubinode/deploy-kvm-vm/tree/v1.0) (2019-09-18)
36+
37+
[Full Changelog](https://github.com/Qubinode/deploy-kvm-vm/compare/df0ed43fe4f709a56e2a7500235b43cea121cdde...v1.0)
38+
39+
40+
41+
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*

defaults/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,18 @@ update_inventory: yes
113113
inventory_file: ""
114114
inventory_group: ""
115115

116+
# Qemu preallocation, options are: metadata, falloc, full
117+
qemu_img_allocation: falloc
118+
116119
#########################
117120
## NO CHANGE REQUIRED
121+
required_packages:
122+
- python3-netaddr
123+
118124
vm_local_hostname: "{{ vm_name }}.{{ vm_domain }}"
119125
vm_hostname: "{{ vm_local_hostname }}"
126+
# get list of os variants
127+
# $ osinfo-query os
120128
os_variant: "{{ os_release }}"
121129
vm_ifcfg: "{{ vm_data_dir }}/{{ vm_name }}/ifcfg"
122130
vm_virtinstall_script: "{{ vm_data_dir }}/{{ vm_name }}/virtinstall.sh"

handlers/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
# handlers file for ansible-role-rhel7-kvm-cloud-init
2+
# handlers file for deploy-kvm-vm

tasks/deploy_vm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@
2424
block:
2525
- name: DEPLOY_VM Create operating system disk for {{ vm_name }}
2626
when: not os_disk_created.stat.exists
27-
command: "qemu-img create -f qcow2 {{ os_disk }} {{ vm_root_disk_size }}G"
27+
command: "qemu-img create -f qcow2 -o preallocation={{ qemu_img_allocation }} {{ os_disk }} {{ vm_root_disk_size }}"
2828
args:
2929
creates: "{{ os_disk }}"
3030
register: create_os_disk
3131

3232
- name: DEPLOY_VM grow {{ vm_name }} operating system
3333
command: >
34-
virt-resize -v -x --expand /dev/sda1 "{{ os_qcow_template }}" "{{ os_disk }}"
34+
sudo virt-resize -v -x --expand /dev/sda1 "{{ os_qcow_template }}" "{{ os_disk }}"
3535
register: resize_create_os_disk
3636
changed_when: '"Resize operation completed with no errors" in resize_create_os_disk.stdout'
3737

tasks/get_ip_info.yml

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
---
2+
- block:
3+
- name: try to discover {{ vm_name }} ip address
4+
command: "/usr/local/bin/getvmip -r {{ vm_name }}"
5+
until: dhcp_vm_ip.stdout != ""
6+
retries: 30
7+
delay: 1
8+
register: dhcp_vm_ip
9+
changed_when: False
10+
rescue:
11+
- debug:
12+
msg: "could not get ip for a vm"
13+
14+
- name: setting vm_ip variable to {{ dhcp_vm_ip.stdout }} dhcp provided ip
15+
set_fact:
16+
vm_ip: "{{ dhcp_vm_ip.stdout }}"
17+
when: vm_ipaddress | length == 0 or not static_ip|bool
18+
19+
- set_fact:
20+
vm_ip_differ: false
21+
22+
- name: check if VM current ip matches the user provided ip
23+
set_fact:
24+
vm_ip_differ: true
25+
when: vm_ipaddress | length != 0 and (dhcp_vm_ip.stdout != vm_ipaddress)
26+
# when: dhcp_vm_ip is not skipped and dhcp_vm_ip.stdout | length != 0
27+
28+
- fail:
29+
msg: "Could not find the ip address for the VM {{ vm_name }}."
30+
when: vm_ip is not defined or vm_ip | length == 0
31+
32+
- name: discover {{ vm_name }} netmask prefix when using DHCP
33+
shell: |
34+
/usr/local/bin/getvmip -a| awk -F'/' '/{{ vm_name }}/ {print $2}'
35+
register: netmask_prefix
36+
changed_when: False
37+
when: vm_mask_prefix is not defined
38+
39+
- name: setting vm_mask_prefix variable to {{ vm_name }} dhcp provided netmask
40+
set_fact:
41+
vm_mask_prefix: "{{ netmask_prefix.stdout }}"
42+
when: netmask_prefix is defined and netmask_prefix is not skipped
43+
44+
- name: discover {{ vm_name }} gateway when using DHCP
45+
shell: |
46+
ip route get 8.8.8.8|awk '/via/ {print $3}'
47+
delegate_to: "{{ vm_name }}"
48+
changed_when: false
49+
register: gateway
50+
when: vm_gateway is not defined
51+
52+
- name: setting vm_gateway variable to {{ vm_name }} dhcp provided gateway
53+
set_fact:
54+
vm_gateway: "{{ gateway.stdout }}"
55+
when: gateway is defined and gateway is not skipped
56+
57+
- name: Get MAC address
58+
shell: >
59+
virsh --connect qemu:///system dumpxml {{ vm_name }} | awk -F\' '/mac address/ {print $2}'
60+
delegate_to: "{{ kvm_install_host }}"
61+
register: vm_mac_result
62+
changed_when: false
63+
when: vm_name in all_instances.list_vms and vm_mac is not defined
64+
65+
- name: setting {{ vm_name }} vm_mac variable to {{ vm_mac_result.stdout }}
66+
set_fact:
67+
vm_mac: "{{ vm_mac_result.stdout }}"
68+
when: vm_name in all_instances.list_vms and vm_mac is not defined
69+
70+
71+
- name: generate {{ vm_name }} ifcfg interface template
72+
template:
73+
src: ifcfg.j2
74+
dest: "{{ vm_ifcfg }}"

tasks/main.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
---
2-
# tasks file for ansible-role-rhel7-kvm-cloud-init
2+
# tasks file for deploy-kvm-vm
3+
4+
- name: Ensure required packages are installed
5+
become: yes
6+
package:
7+
name: "{{ required_packages }}"
8+
state: present
9+
310
- name: convert disk size to bytes
411
vars:
512
new_size: "{{ vm_root_disk_size }} GB"

tasks/post_config.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
- name: POST_CONFIG Eject CD-Rom
4141
shell: >
4242
virsh change-media {{ vm_name }} {{ cdrom_device.stdout.split()[0] }} --eject
43-
ignore_errors: yes
44-
when: cdrom_device.stdout.split()[0] != ""
43+
when: cdrom_device.stdout != '' and cdrom_device.stdout.split()[0] != ""
4544

4645
- name: POST_CONFIG display vm information
4746
debug:

tasks/set_dhcp_to_static.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,6 @@
6868
/usr/local/bin/qubi-virt-customize -a {{ os_disk }} --upload {{ vm_ifcfg }}:/etc/sysconfig/network-scripts/ifcfg-{{ vm_nic }}
6969
register: uploaded_static_ip
7070
when: vm_ip_differ|bool
71-
71+
7272
- name: SET-DHCP-TO-STATIC startup VM
7373
import_tasks: startup_vm.yml

templates/ifcfg.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ DEVICE={{ vm_nic }}
33
ONBOOT=yes
44
TYPE=Ethernet
55
USERCTL=no
6-
{% if static_net %}
6+
{% if static_net == true %}
77
BOOTPROTO=none
88
PEERDNS=yes
99
NM_CONTROLLED=yes
1010
IPADDR={{ vm_ip }}
1111
GATEWAY={{ vm_gateway }}
1212
PREFIX={{ vm_cidr }}
13-
{% else %}
13+
{% else %}
1414
BOOTPROTO=dhcp
1515
PEERDNS=yes
1616
NM_CONTROLLED=yes

templates/virt-install-cmd.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ virt-install --connect qemu:///system \
1111
--os-type Linux \
1212
--os-variant {{ os_variant }} \
1313
--virt-type kvm \
14-
--noautoconsole \
15-
--autostart
14+
--noautoconsole
15+
// --autostart
1616

1717
exit 0

0 commit comments

Comments
 (0)