diff --git a/defaults/main.yml b/defaults/main.yml index aacd5cf..74b10ce 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -32,6 +32,7 @@ libvirt_pkgs: - java-1.8.0-openjdk-devel.x86_64 - tmux - patch + - python-dns libvirt_services: - libvirtd @@ -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" diff --git a/tasks/bridge_interface.yml b/tasks/bridge_interface.yml index 777801b..12e4231 100644 --- a/tasks/bridge_interface.yml +++ b/tasks/bridge_interface.yml @@ -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. @@ -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 \ No newline at end of file + when: create_bridge_device.changed or create_slave_device.changed diff --git a/tasks/configure_shell.yml b/tasks/configure_shell.yml index 30675fa..df5593c 100644 --- a/tasks/configure_shell.yml +++ b/tasks/configure_shell.yml @@ -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 - diff --git a/tasks/main.yml b/tasks/main.yml index a077027..79ddf7d 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -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 @@ -30,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 diff --git a/tasks/storage_pool.yml b/tasks/storage_pool.yml index bfbdce2..4dc87e9 100644 --- a/tasks/storage_pool.yml +++ b/tasks/storage_pool.yml @@ -16,4 +16,4 @@ virt_pool: autostart: "{{ item.autostart }}" name: "{{ item.name }}" - with_items: "{{ libvirt_host_storage_pools }}" \ No newline at end of file + with_items: "{{ libvirt_host_storage_pools }}" diff --git a/tasks/verify_variables.yml b/tasks/verify_variables.yml new file mode 100644 index 0000000..b6afd22 --- /dev/null +++ b/tasks/verify_variables.yml @@ -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 diff --git a/templates/br_network.xml.j2 b/templates/br_network.xml.j2 index 17c5c9e..963e7d3 100644 --- a/templates/br_network.xml.j2 +++ b/templates/br_network.xml.j2 @@ -1,5 +1,5 @@ - {{ item.name }} - - - \ No newline at end of file + {{ libvirt_host_networks[1].name }} + + + diff --git a/templates/ifcfg_bridge_template.j2 b/templates/ifcfg_bridge_template.j2 index d644568..6d647f5 100644 --- a/templates/ifcfg_bridge_template.j2 +++ b/templates/ifcfg_bridge_template.j2 @@ -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 \ No newline at end of file +DELAY=0 diff --git a/templates/ifcfg_device_template.j2 b/templates/ifcfg_device_template.j2 index 687d00c..ae73803 100644 --- a/templates/ifcfg_device_template.j2 +++ b/templates/ifcfg_device_template.j2 @@ -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 diff --git a/templates/nat_network.xml.j2 b/templates/nat_network.xml.j2 index 20bf453..320f47f 100644 --- a/templates/nat_network.xml.j2 +++ b/templates/nat_network.xml.j2 @@ -1,10 +1,10 @@ {{ item.name }} - + - bootstrap.{{ item.int_domain }} + bootstrap.{{ item.external_domain }} api-int.{{ item.external_domain }} @@ -13,24 +13,29 @@ {% for id in range(0, item.master_count | int) -%} - master-{{ id }}.{{ item.int_domain }} + master-{{ id }}.{{ item.external_domain }} etcd-{{ id }}.{{ item.external_domain }} {% endfor %} + {% for id in range(0, item.compute_count | int) -%} + + compute-{{ id }}.{{ item.external_domain }} + + {% endfor %} - + {% for id in range(0, item.master_count | int) -%} - + {% endfor -%} {% for id in range(0, item.compute_count | int) -%} - + {% endfor %} - \ No newline at end of file +