Skip to content

Commit 9f79a01

Browse files
author
Rodrique Heron
committed
Merge branch 'tosin2013-ocp4'
2 parents e122870 + dffa71e commit 9f79a01

File tree

10 files changed

+181
-52
lines changed

10 files changed

+181
-52
lines changed

defaults/main.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ libvirt_pkgs:
3232
- java-1.8.0-openjdk-devel.x86_64
3333
- tmux
3434
- patch
35+
- python-dns
3536

3637
libvirt_services:
3738
- libvirtd
@@ -61,13 +62,20 @@ libvirt_host_networks:
6162
bridge_device: "{{ qubinode_bridge_name }}"
6263
xml_file: "br_network.xml.j2"
6364

64-
kvm_host_ip: ""
65-
kvm_host_interface: ""
66-
kvm_host_gw: ""
67-
kvm_host_macaddr: ""
68-
kvm_bridge_type: "Bridge"
69-
kvm_host_bootproto: ""
70-
kvm_host_mask_prefix: ""
65+
libvirt_host_networks: []
66+
kvm_host_ipaddr: "{{ ansible_default_ipv4.address }}"
67+
kvm_host_interface: "{{ ansible_default_ipv4.interface }}"
68+
kvm_host_gw: "{{ ansible_default_ipv4.gateway }}"
69+
kvm_host_macaddr: "{{ ansible_default_ipv4.macaddress }}"
70+
kvm_host_netmask: "{{ ansible_default_ipv4.netmask }}"
71+
kvm_host_bootproto: 'dhcp'
72+
kvm_bridge_type: 'Bridge'
73+
storage_nic: false
74+
libvirt_disk: false
75+
use_dns: idm # use idm or use libvirt
76+
77+
kvm_host_ip: "{{ kvm_host_ipaddr }}"
78+
kvm_host_mask_prefix: "{{ kvm_host_netmask }}"
7179
ssh_username: ""
7280
kvm_host_domain: "lab.example"
7381
kvm_host_dns_server: "1.1.1.1"

tasks/bridge_interface.yml

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,46 @@
11
---
2+
- name: Display all variables/facts known for a host
3+
debug:
4+
var: libvirt_host_networks[1]
5+
6+
- fail: msg="Bailing out. this play requires libvirt_host_networks[1].bridge_device"
7+
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
8+
when:
9+
- libvirt_host_networks[1].bridge_device |length == 0
10+
- libvirt_host_networks[1].mode == 'bridge'
11+
212
- name: delete any previous failed attempts to configure bridge interface
313
file:
4-
path: /etc/sysconfig/network-scripts/ifcfg-
14+
path: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_device }}
515
state: absent
16+
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
17+
when: libvirt_host_networks[1].mode == 'bridge'
618

719
- name: setup bridge interface
820
template:
921
src: ifcfg_bridge_template.j2
10-
dest: /etc/sysconfig/network-scripts/ifcfg-{{ item.bridge_device }}
22+
dest: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_device }}
1123
mode: 0640
12-
with_items: "{{ libvirt_host_networks }}"
13-
when: item.mode == 'bridge'
14-
register: bridge_device
24+
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
25+
when: libvirt_host_networks[1].mode == 'bridge'
26+
register: create_bridge_device
1527
become: True
1628

29+
- fail: msg="Bailing out. this play requires libvirt_host_networks[1].bridge_slave_dev"
30+
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
31+
when:
32+
- libvirt_host_networks[1].bridge_slave_dev |length == 0
33+
- libvirt_host_networks[1].mode == 'bridge'
34+
1735
- name: setup ethernet device interface
1836
template:
1937
src: ifcfg_device_template.j2
20-
dest: /etc/sysconfig/network-scripts/ifcfg-{{ item.bridge_slave_dev }}
38+
dest: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_slave_dev }}
2139
mode: 0640
22-
with_items: "{{ libvirt_host_networks }}"
40+
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
2341
become: True
24-
register: slave_device
25-
when: item.mode == 'bridge'
42+
register: create_slave_device
43+
when: libvirt_host_networks[1].mode == 'bridge'
2644

2745
# Using the systemd module to restart networking seems to not properly panos_restart
2846
# the networking subsystem, further debugging is required to find root issue.
@@ -37,10 +55,10 @@
3755
- network
3856
- NetworkManager
3957
- libvirtd
40-
when: bridge_device.changed or slave_device.changed
58+
when: create_bridge_device.changed or create_slave_device.changed
4159

4260
- name: update /etc/resolv.conf
4361
template:
4462
src: resolv.conf.j2
4563
dest: /etc/resolv.conf
46-
when: bridge_device.changed or slave_device.changed
64+
when: create_bridge_device.changed or create_slave_device.changed

tasks/configure_shell.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,23 @@
66
become: True
77

88
- name: Replace .bash_profile file
9-
copy:
9+
copy:
1010
src: bash_profile.sh
1111
dest: "/home/{{ ssh_username }}/.bash_profile"
1212
backup: yes
1313
become: True
1414

1515
- name: Replace .bash_aliases file
16-
copy:
16+
copy:
1717
src: bash_aliases.sh
1818
dest: "/home/{{ ssh_username }}/.bash_aliases"
1919
backup: yes
2020
become: True
2121

22-
22+
2323
- name: Replace .bash_logout file
24-
copy:
24+
copy:
2525
src: bash_logout.sh
2626
dest: "/home/{{ ssh_username }}/.bash_logout"
2727
backup: yes
2828
become: True
29-

tasks/main.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
---
2+
- name: Display all variables/facts known for a host
3+
debug:
4+
var: libvirt_host_networks
5+
6+
7+
- name: validate variables are defined
8+
include_tasks: verify_variables.yml
29

310
- name: validate virtualization extensions are available to this host
411
include_tasks: validate.yml
@@ -15,7 +22,6 @@
1522
register: pkg_installed
1623
changed_when: pkg_installed.stdout == 'yes'
1724

18-
1925
- name: enable libvirt services
2026
service:
2127
name: "{{ item }}"
@@ -31,10 +37,10 @@
3137
- name: configure bridge interface for libvirt
3238
include_tasks: bridge_interface.yml
3339
when: configure_bridge
34-
40+
3541
- name: configure libvirt network
3642
include_tasks: networks.yml
37-
43+
3844
- name: configure libvirt storage pool
3945
include_tasks: storage_pool.yml
4046

tasks/storage_pool.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
virt_pool:
1717
autostart: "{{ item.autostart }}"
1818
name: "{{ item.name }}"
19-
with_items: "{{ libvirt_host_storage_pools }}"
19+
with_items: "{{ libvirt_host_storage_pools }}"

tasks/verify_variables.yml

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
---
2+
- fail: msg="Bailing out. this play requires 'kvm_host_ip' KVM host ip"
3+
when: kvm_host_ip |length == 0
4+
5+
- fail: msg="Bailing out. this play requires 'kvm_host_interface' KVM host interface"
6+
when: kvm_host_interface |length == 0
7+
8+
- fail: msg="Bailing out. this play requires 'kvm_host_mask_prefix' KVM subnet mask prefix"
9+
when: kvm_host_mask_prefix is undefined
10+
11+
- fail: msg="Bailing out. this play requires 'kvm_host_gw' KVM host kvm host gateway"
12+
when: kvm_host_gw |length == 0
13+
14+
- fail: msg="Bailing out. this play requires 'ssh_username' ssh username"
15+
when: ssh_username |length == 0
16+
17+
- fail: msg="Bailing out. this play requires 'kvm_host_domain' kvm host domain"
18+
when: kvm_host_domain |length == 0
19+
20+
- fail: msg="Bailing out. this play requires 'kvm_host_dns_server' kvm host dns server"
21+
when: kvm_host_dns_server |length == 0
22+
23+
- fail: msg="Bailing out. this play requires 'kvm_host_bootproto' KVM host bootproto"
24+
when: kvm_host_bootproto |length == 0
25+
26+
- fail: msg="Bailing out. this play requires 'kvm_bridge_type' KVM bridge type"
27+
when: kvm_bridge_type |length == 0
28+
29+
- fail: msg="Bailing out. this play requires 'qubinode_bridge_name' qubinode bridge name"
30+
when: qubinode_bridge_name |length == 0
31+
32+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mac_start' MAC start not found for nat network"
33+
when: libvirt_host_networks[0].mac_start |length == 0
34+
35+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mac' MAC not found for Bridge network"
36+
when: libvirt_host_networks[1].mac |length == 0
37+
38+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].name' Name not found for nat network"
39+
when: libvirt_host_networks[0].name |length == 0
40+
41+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].name' Name not found for Bridge network"
42+
when: libvirt_host_networks[1].name |length == 0
43+
44+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].create' create bool not found for nat network"
45+
when: libvirt_host_networks[0].create is undefined
46+
47+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].create' create bool not found for Bridge network"
48+
when: libvirt_host_networks[1].create is undefined
49+
50+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mode' mode not found for nat network"
51+
when: libvirt_host_networks[0].mode |length == 0
52+
53+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mode' mode not found for Bridge network"
54+
when: libvirt_host_networks[1].mode |length == 0
55+
56+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].int_domain' Internal Domain not found for NAT network"
57+
when: libvirt_host_networks[0].int_domain |length == 0
58+
59+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].bridge_device' bridge device not found for Bridge network"
60+
when: libvirt_host_networks[1].bridge_device |length == 0
61+
62+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].external_domain' External Domain not found for NAT network"
63+
when: libvirt_host_networks[0].external_domain |length == 0
64+
65+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ifcfg_type' ifcfg_type not found for Bridge network"
66+
when: libvirt_host_networks[1].ifcfg_type |length == 0
67+
68+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].master_count' Master count not found for NAT network"
69+
when: libvirt_host_networks[0].master_count is undefined
70+
71+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].compute_count' Computer Count not found for NAT network"
72+
when: libvirt_host_networks[0].compute_count is undefined
73+
74+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].subnet' subnet not found for NAT network"
75+
when: libvirt_host_networks[0].subnet |length == 0
76+
77+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mask' subnet mask not found for NAT network"
78+
when: libvirt_host_networks[0].mask |length == 0
79+
80+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ifcfg_bootproto' ifcfg_bootproto not found for Bridge network"
81+
when: libvirt_host_networks[1].ifcfg_bootproto |length == 0
82+
83+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].bridge_slave_dev' bridge_slave_dev not found for Bridge network"
84+
when: libvirt_host_networks[1].bridge_slave_dev |length == 0
85+
86+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].gateway' gateway not found for Bridge network"
87+
when: libvirt_host_networks[1].gateway |length == 0
88+
89+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mask_prefix' mask_prefix not found for Bridge network"
90+
when: libvirt_host_networks[1].mask_prefix is undefined
91+
92+
- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ipaddress' ipaddress not found for Bridge network"
93+
when: libvirt_host_networks[1].ipaddress |length == 0

templates/br_network.xml.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<network connections='1'>
2-
<name>{{ item.name }}</name>
3-
<forward mode='{{ item.mode }}'/>
4-
<bridge name='{{ item.bridge_device }}'/>
5-
</network>
2+
<name>{{ libvirt_host_networks[1].name }}</name>
3+
<forward mode='{{ libvirt_host_networks[1].mode }}'/>
4+
<bridge name='{{ libvirt_host_networks[1].bridge_device }}'/>
5+
</network>

templates/ifcfg_bridge_template.j2

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
DEVICE={{ item.bridge_device }}
2-
NAME={{ item.bridge_device }}
3-
TYPE={{ item.ifcfg_type }}
1+
DEVICE={{ libvirt_host_networks[1].bridge_device }}
2+
NAME={{ libvirt_host_networks[1].bridge_device }}
3+
TYPE={{ libvirt_host_networks[1].ifcfg_type }}
44
ONBOOT=yes
5-
{% if item.ifcfg_bootproto == "dhcp" %}
6-
BOOTPROTO={{ item.ifcfg_bootproto }}
7-
{% elif item.ifcfg_bootproto == "none" %}
5+
{% if libvirt_host_networks[1].ifcfg_bootproto == "dhcp" %}
6+
BOOTPROTO={{ libvirt_host_networks[1].ifcfg_bootproto }}
7+
{% elif libvirt_host_networks[1].ifcfg_bootproto == "none" %}
88
BOOTPROTO=static
9-
IPADDR={{ item.ipaddress }}
10-
GATEWAY={{ item.gateway }}
11-
PREFIX={{ item.mask_prefix }}
9+
IPADDR={{ libvirt_host_networks[1].ipaddress }}
10+
GATEWAY={{ libvirt_host_networks[1].gateway }}
11+
PREFIX={{ libvirt_host_networks[1].mask_prefix }}
1212
{% endif %}
1313
ZONE=public
14-
DELAY=0
14+
DELAY=0

templates/ifcfg_device_template.j2

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
DEVICE={{ item.bridge_slave_dev }}
2-
NAME={{ item.bridge_device }}_slave
1+
DEVICE={{ libvirt_host_networks[1].bridge_slave_dev }}
2+
NAME={{ libvirt_host_networks[1].bridge_device }}_slave
33
TYPE=Ethernet
4-
HWADDR={{ item.mac }}
4+
HWADDR={{ libvirt_host_networks[1].mac }}
55
BOOTPROTO=none
66
ONBOOT=yes
7-
BRIDGE={{ item.bridge_device }}
7+
BRIDGE={{ libvirt_host_networks[1].bridge_device }}
88
ZONE=public

templates/nat_network.xml.j2

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
<network>
22
<name>{{ item.name }}</name>
33
<forward mode='{{ item.mode }}'/>
4-
<domain name="{{ item.int_domain }}"/>
4+
<domain name="{{ item.external_domain }}"/>
55
<dns>
66
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.2'>
7-
<hostname>bootstrap.{{ item.int_domain }}</hostname>
7+
<hostname>bootstrap.{{ item.external_domain }}</hostname>
88
</host>
99
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.1'>
1010
<hostname>api-int.{{ item.external_domain }}</hostname>
@@ -13,24 +13,29 @@
1313
{% for id in range(0, item.master_count | int) -%}
1414
<srv service='etcd-server-ssl' protocol='tcp' domain='{{ item.external_domain }}' target='etcd-{{ id }}.{{ item.external_domain }}' port='2380' priority='0' weight='10'/>
1515
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + id|int }}'>
16-
<hostname>master-{{ id }}.{{ item.int_domain }}</hostname>
16+
<hostname>master-{{ id }}.{{ item.external_domain }}</hostname>
1717
<hostname>etcd-{{ id }}.{{ item.external_domain }}</hostname>
1818
</host>
1919
{% endfor %}
20+
{% for id in range(0, item.compute_count | int) -%}
21+
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 13 + id|int }}'>
22+
<hostname>compute-{{ id }}.{{ item.external_domain }}</hostname>
23+
</host>
24+
{% endfor %}
2025
</dns>
2126

2227
<ip address='{{ item.subnet.split('.')[:3] | join('.')}}.1' netmask='{{ item.mask }}'>
2328
<dhcp>
2429
<range start='{{ item.subnet.split('.')[:3] | join('.')}}.10' end='{{ item.subnet.split('.')[:3] | join('.')}}.250'/>
25-
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % 2 }}' name='bootstrap.{{ item.int_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.2'/>
30+
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % 2 }}' name='bootstrap.{{ item.external_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.2'/>
2631

2732
{% for id in range(0, item.master_count | int) -%}
28-
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % (10 + id) }}' name='master-{{ id }}.{{ item.int_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + id }}'/>
33+
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % (10 + id) }}' name='master-{{ id }}.{{ item.external_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + id }}'/>
2934
{% endfor -%}
3035

3136
{% for id in range(0, item.compute_count | int) -%}
32-
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % (10 + item.master_count|int + id) }}' name='compute-{{ id }}.{{ item.int_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + item.master_count|int + id }}'/>
37+
<host mac='{{ item.mac_start }}{{ '%02x' % item.subnet.split('.')[1]|int }}:{{ '%02x' % item.subnet.split('.')[2]|int }}:{{ '%02x' % (10 + item.master_count|int + id) }}' name='compute-{{ id }}.{{ item.external_domain }}' ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + item.master_count|int + id }}'/>
3338
{% endfor %}
3439
</dhcp>
3540
</ip>
36-
</network>
41+
</network>

0 commit comments

Comments
 (0)