Skip to content

Commit

Permalink
Merge branch 'tosin2013-ocp4'
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrique Heron committed Dec 28, 2019
2 parents e122870 + dffa71e commit 9f79a01
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 52 deletions.
22 changes: 15 additions & 7 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ libvirt_pkgs:
- java-1.8.0-openjdk-devel.x86_64
- tmux
- patch
- python-dns

libvirt_services:
- libvirtd
Expand Down Expand Up @@ -61,13 +62,20 @@ libvirt_host_networks:
bridge_device: "{{ qubinode_bridge_name }}"
xml_file: "br_network.xml.j2"

kvm_host_ip: ""
kvm_host_interface: ""
kvm_host_gw: ""
kvm_host_macaddr: ""
kvm_bridge_type: "Bridge"
kvm_host_bootproto: ""
kvm_host_mask_prefix: ""
libvirt_host_networks: []
kvm_host_ipaddr: "{{ ansible_default_ipv4.address }}"
kvm_host_interface: "{{ ansible_default_ipv4.interface }}"
kvm_host_gw: "{{ ansible_default_ipv4.gateway }}"
kvm_host_macaddr: "{{ ansible_default_ipv4.macaddress }}"
kvm_host_netmask: "{{ ansible_default_ipv4.netmask }}"
kvm_host_bootproto: 'dhcp'
kvm_bridge_type: 'Bridge'
storage_nic: false
libvirt_disk: false
use_dns: idm # use idm or use libvirt

kvm_host_ip: "{{ kvm_host_ipaddr }}"
kvm_host_mask_prefix: "{{ kvm_host_netmask }}"
ssh_username: ""
kvm_host_domain: "lab.example"
kvm_host_dns_server: "1.1.1.1"
Expand Down
40 changes: 29 additions & 11 deletions tasks/bridge_interface.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
---
- name: Display all variables/facts known for a host
debug:
var: libvirt_host_networks[1]

- fail: msg="Bailing out. this play requires libvirt_host_networks[1].bridge_device"
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
when:
- libvirt_host_networks[1].bridge_device |length == 0
- libvirt_host_networks[1].mode == 'bridge'

- name: delete any previous failed attempts to configure bridge interface
file:
path: /etc/sysconfig/network-scripts/ifcfg-
path: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_device }}
state: absent
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
when: libvirt_host_networks[1].mode == 'bridge'

- name: setup bridge interface
template:
src: ifcfg_bridge_template.j2
dest: /etc/sysconfig/network-scripts/ifcfg-{{ item.bridge_device }}
dest: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_device }}
mode: 0640
with_items: "{{ libvirt_host_networks }}"
when: item.mode == 'bridge'
register: bridge_device
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
when: libvirt_host_networks[1].mode == 'bridge'
register: create_bridge_device
become: True

- fail: msg="Bailing out. this play requires libvirt_host_networks[1].bridge_slave_dev"
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
when:
- libvirt_host_networks[1].bridge_slave_dev |length == 0
- libvirt_host_networks[1].mode == 'bridge'

- name: setup ethernet device interface
template:
src: ifcfg_device_template.j2
dest: /etc/sysconfig/network-scripts/ifcfg-{{ item.bridge_slave_dev }}
dest: /etc/sysconfig/network-scripts/ifcfg-{{ libvirt_host_networks[1].bridge_slave_dev }}
mode: 0640
with_items: "{{ libvirt_host_networks }}"
with_libvirt_host_networks[1]s: "{{ libvirt_host_networks[1] }}"
become: True
register: slave_device
when: item.mode == 'bridge'
register: create_slave_device
when: libvirt_host_networks[1].mode == 'bridge'

# Using the systemd module to restart networking seems to not properly panos_restart
# the networking subsystem, further debugging is required to find root issue.
Expand All @@ -37,10 +55,10 @@
- network
- NetworkManager
- libvirtd
when: bridge_device.changed or slave_device.changed
when: create_bridge_device.changed or create_slave_device.changed

- name: update /etc/resolv.conf
template:
src: resolv.conf.j2
dest: /etc/resolv.conf
when: bridge_device.changed or slave_device.changed
when: create_bridge_device.changed or create_slave_device.changed
9 changes: 4 additions & 5 deletions tasks/configure_shell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,23 @@
become: True

- name: Replace .bash_profile file
copy:
copy:
src: bash_profile.sh
dest: "/home/{{ ssh_username }}/.bash_profile"
backup: yes
become: True

- name: Replace .bash_aliases file
copy:
copy:
src: bash_aliases.sh
dest: "/home/{{ ssh_username }}/.bash_aliases"
backup: yes
become: True


- name: Replace .bash_logout file
copy:
copy:
src: bash_logout.sh
dest: "/home/{{ ssh_username }}/.bash_logout"
backup: yes
become: True

12 changes: 9 additions & 3 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
- name: Display all variables/facts known for a host
debug:
var: libvirt_host_networks


- name: validate variables are defined
include_tasks: verify_variables.yml

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


- name: enable libvirt services
service:
name: "{{ item }}"
Expand All @@ -31,10 +37,10 @@
- name: configure bridge interface for libvirt
include_tasks: bridge_interface.yml
when: configure_bridge

- name: configure libvirt network
include_tasks: networks.yml

- name: configure libvirt storage pool
include_tasks: storage_pool.yml

Expand Down
2 changes: 1 addition & 1 deletion tasks/storage_pool.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
virt_pool:
autostart: "{{ item.autostart }}"
name: "{{ item.name }}"
with_items: "{{ libvirt_host_storage_pools }}"
with_items: "{{ libvirt_host_storage_pools }}"
93 changes: 93 additions & 0 deletions tasks/verify_variables.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
---
- fail: msg="Bailing out. this play requires 'kvm_host_ip' KVM host ip"
when: kvm_host_ip |length == 0

- fail: msg="Bailing out. this play requires 'kvm_host_interface' KVM host interface"
when: kvm_host_interface |length == 0

- fail: msg="Bailing out. this play requires 'kvm_host_mask_prefix' KVM subnet mask prefix"
when: kvm_host_mask_prefix is undefined

- fail: msg="Bailing out. this play requires 'kvm_host_gw' KVM host kvm host gateway"
when: kvm_host_gw |length == 0

- fail: msg="Bailing out. this play requires 'ssh_username' ssh username"
when: ssh_username |length == 0

- fail: msg="Bailing out. this play requires 'kvm_host_domain' kvm host domain"
when: kvm_host_domain |length == 0

- fail: msg="Bailing out. this play requires 'kvm_host_dns_server' kvm host dns server"
when: kvm_host_dns_server |length == 0

- fail: msg="Bailing out. this play requires 'kvm_host_bootproto' KVM host bootproto"
when: kvm_host_bootproto |length == 0

- fail: msg="Bailing out. this play requires 'kvm_bridge_type' KVM bridge type"
when: kvm_bridge_type |length == 0

- fail: msg="Bailing out. this play requires 'qubinode_bridge_name' qubinode bridge name"
when: qubinode_bridge_name |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mac_start' MAC start not found for nat network"
when: libvirt_host_networks[0].mac_start |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mac' MAC not found for Bridge network"
when: libvirt_host_networks[1].mac |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].name' Name not found for nat network"
when: libvirt_host_networks[0].name |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].name' Name not found for Bridge network"
when: libvirt_host_networks[1].name |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].create' create bool not found for nat network"
when: libvirt_host_networks[0].create is undefined

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].create' create bool not found for Bridge network"
when: libvirt_host_networks[1].create is undefined

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mode' mode not found for nat network"
when: libvirt_host_networks[0].mode |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mode' mode not found for Bridge network"
when: libvirt_host_networks[1].mode |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].int_domain' Internal Domain not found for NAT network"
when: libvirt_host_networks[0].int_domain |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].bridge_device' bridge device not found for Bridge network"
when: libvirt_host_networks[1].bridge_device |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].external_domain' External Domain not found for NAT network"
when: libvirt_host_networks[0].external_domain |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ifcfg_type' ifcfg_type not found for Bridge network"
when: libvirt_host_networks[1].ifcfg_type |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].master_count' Master count not found for NAT network"
when: libvirt_host_networks[0].master_count is undefined

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].compute_count' Computer Count not found for NAT network"
when: libvirt_host_networks[0].compute_count is undefined

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].subnet' subnet not found for NAT network"
when: libvirt_host_networks[0].subnet |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[0].mask' subnet mask not found for NAT network"
when: libvirt_host_networks[0].mask |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ifcfg_bootproto' ifcfg_bootproto not found for Bridge network"
when: libvirt_host_networks[1].ifcfg_bootproto |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].bridge_slave_dev' bridge_slave_dev not found for Bridge network"
when: libvirt_host_networks[1].bridge_slave_dev |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].gateway' gateway not found for Bridge network"
when: libvirt_host_networks[1].gateway |length == 0

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].mask_prefix' mask_prefix not found for Bridge network"
when: libvirt_host_networks[1].mask_prefix is undefined

- fail: msg="Bailing out. this play requires 'libvirt_host_networks[1].ipaddress' ipaddress not found for Bridge network"
when: libvirt_host_networks[1].ipaddress |length == 0
8 changes: 4 additions & 4 deletions templates/br_network.xml.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<network connections='1'>
<name>{{ item.name }}</name>
<forward mode='{{ item.mode }}'/>
<bridge name='{{ item.bridge_device }}'/>
</network>
<name>{{ libvirt_host_networks[1].name }}</name>
<forward mode='{{ libvirt_host_networks[1].mode }}'/>
<bridge name='{{ libvirt_host_networks[1].bridge_device }}'/>
</network>
20 changes: 10 additions & 10 deletions templates/ifcfg_bridge_template.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
DEVICE={{ item.bridge_device }}
NAME={{ item.bridge_device }}
TYPE={{ item.ifcfg_type }}
DEVICE={{ libvirt_host_networks[1].bridge_device }}
NAME={{ libvirt_host_networks[1].bridge_device }}
TYPE={{ libvirt_host_networks[1].ifcfg_type }}
ONBOOT=yes
{% if item.ifcfg_bootproto == "dhcp" %}
BOOTPROTO={{ item.ifcfg_bootproto }}
{% elif item.ifcfg_bootproto == "none" %}
{% if libvirt_host_networks[1].ifcfg_bootproto == "dhcp" %}
BOOTPROTO={{ libvirt_host_networks[1].ifcfg_bootproto }}
{% elif libvirt_host_networks[1].ifcfg_bootproto == "none" %}
BOOTPROTO=static
IPADDR={{ item.ipaddress }}
GATEWAY={{ item.gateway }}
PREFIX={{ item.mask_prefix }}
IPADDR={{ libvirt_host_networks[1].ipaddress }}
GATEWAY={{ libvirt_host_networks[1].gateway }}
PREFIX={{ libvirt_host_networks[1].mask_prefix }}
{% endif %}
ZONE=public
DELAY=0
DELAY=0
8 changes: 4 additions & 4 deletions templates/ifcfg_device_template.j2
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
DEVICE={{ item.bridge_slave_dev }}
NAME={{ item.bridge_device }}_slave
DEVICE={{ libvirt_host_networks[1].bridge_slave_dev }}
NAME={{ libvirt_host_networks[1].bridge_device }}_slave
TYPE=Ethernet
HWADDR={{ item.mac }}
HWADDR={{ libvirt_host_networks[1].mac }}
BOOTPROTO=none
ONBOOT=yes
BRIDGE={{ item.bridge_device }}
BRIDGE={{ libvirt_host_networks[1].bridge_device }}
ZONE=public
19 changes: 12 additions & 7 deletions templates/nat_network.xml.j2
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<network>
<name>{{ item.name }}</name>
<forward mode='{{ item.mode }}'/>
<domain name="{{ item.int_domain }}"/>
<domain name="{{ item.external_domain }}"/>
<dns>
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.2'>
<hostname>bootstrap.{{ item.int_domain }}</hostname>
<hostname>bootstrap.{{ item.external_domain }}</hostname>
</host>
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.1'>
<hostname>api-int.{{ item.external_domain }}</hostname>
Expand All @@ -13,24 +13,29 @@
{% for id in range(0, item.master_count | int) -%}
<srv service='etcd-server-ssl' protocol='tcp' domain='{{ item.external_domain }}' target='etcd-{{ id }}.{{ item.external_domain }}' port='2380' priority='0' weight='10'/>
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 10 + id|int }}'>
<hostname>master-{{ id }}.{{ item.int_domain }}</hostname>
<hostname>master-{{ id }}.{{ item.external_domain }}</hostname>
<hostname>etcd-{{ id }}.{{ item.external_domain }}</hostname>
</host>
{% endfor %}
{% for id in range(0, item.compute_count | int) -%}
<host ip='{{ item.subnet.split('.')[:3] | join('.')}}.{{ 13 + id|int }}'>
<hostname>compute-{{ id }}.{{ item.external_domain }}</hostname>
</host>
{% endfor %}
</dns>

<ip address='{{ item.subnet.split('.')[:3] | join('.')}}.1' netmask='{{ item.mask }}'>
<dhcp>
<range start='{{ item.subnet.split('.')[:3] | join('.')}}.10' end='{{ item.subnet.split('.')[:3] | join('.')}}.250'/>
<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'/>
<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'/>

{% for id in range(0, item.master_count | int) -%}
<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 }}'/>
<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 }}'/>
{% endfor -%}

{% for id in range(0, item.compute_count | int) -%}
<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 }}'/>
<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 }}'/>
{% endfor %}
</dhcp>
</ip>
</network>
</network>

0 comments on commit 9f79a01

Please sign in to comment.