diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2018-03-13 05:01:30 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2018-03-13 05:01:30 +0100 |
commit | 006f333828db373435daa15483d2ab753048f62a (patch) | |
tree | 4ae2bedeeb46e69893ee28f96b7d2d48d37549dc /roles/ands_network | |
parent | 0db2995395d28caf4676ab566085b7c66130b629 (diff) | |
download | ands-006f333828db373435daa15483d2ab753048f62a.tar.gz ands-006f333828db373435daa15483d2ab753048f62a.tar.bz2 ands-006f333828db373435daa15483d2ab753048f62a.tar.xz ands-006f333828db373435daa15483d2ab753048f62a.zip |
Production
Diffstat (limited to 'roles/ands_network')
-rw-r--r-- | roles/ands_network/defaults/main.yml | 1 | ||||
-rw-r--r-- | roles/ands_network/tasks/nm_configure.yml | 39 | ||||
-rw-r--r-- | roles/ands_network/tasks/nm_configure_connection.yml | 51 |
3 files changed, 91 insertions, 0 deletions
diff --git a/roles/ands_network/defaults/main.yml b/roles/ands_network/defaults/main.yml new file mode 100644 index 0000000..139e8b3 --- /dev/null +++ b/roles/ands_network/defaults/main.yml @@ -0,0 +1 @@ +configure_network: "{{ ands_configure_network | default(false) }}" diff --git a/roles/ands_network/tasks/nm_configure.yml b/roles/ands_network/tasks/nm_configure.yml new file mode 100644 index 0000000..4482705 --- /dev/null +++ b/roles/ands_network/tasks/nm_configure.yml @@ -0,0 +1,39 @@ + +- name: install needed network manager libs + yum: name='{{ item }}' state=installed + with_items: + - NetworkManager-glib + - nm-connection-editor + - libsemanage-python + - policycoreutils-python + +# Works in 2.4.3.0 with couple of upstream patches +# Infiniband is not supported yet +#- name: configure storage network interface +# nmcli: type=inifinband conn_name=storage ifname="{{ ands_storage_interface }}" ip4="{{ ands_storage_cidr }}" state="present" autoconnect="yes" + + +- name: configure storage nework + include_tasks: nm_configure_connection.yml + vars: + name: "storage" + iface: "{{ ands_storage_interface }}" + cidr: "{{ ands_storage_cidr }}" + force: true + +- name: configure openshift nework + include_tasks: nm_configure_connection.yml + vars: + name: "openshift" + iface: "{{ ands_inner_interface }}" + cidr: "{{ ands_openshift_cidr }}" + force: true + +- name: configure public nework + include_tasks: nm_configure_connection.yml + vars: + name: "storage" + iface: "{{ ands_public_interface }}" + cidr: "{{ ands_openshift_public_cidr }}" + alias: true + diff --git a/roles/ands_network/tasks/nm_configure_connection.yml b/roles/ands_network/tasks/nm_configure_connection.yml new file mode 100644 index 0000000..18fc91e --- /dev/null +++ b/roles/ands_network/tasks/nm_configure_connection.yml @@ -0,0 +1,51 @@ +- name: "detect nm connection corresponding to interface '{{ iface }}'" + shell: "nmcli d show {{ iface | quote }} | grep CONNECTION | cut -d ':' -f 2- | sed -E -e 's/^[[:space:]]+//' | grep '^[[:alpha:]]'" + register: conres + failed_when: false + changed_when: false + + +- name: "check if the requested ip '{{ cidr }}' is present on the interface '{{ iface }}'" + set_fact: + ip_present: "{{ cidr | ipaddr('address') in ips }}" + vars: + eth: "{{ hostvars[inventory_hostname]['ansible_' + iface] | default({}) }}" + ipv4: "{{ eth['ipv4'] | default({}) }}" + q: "{{ eth | json_query('ipv4_secondaries[*].address') }}" + sec: "{{ ((q == ands_none) or (q == '')) | ternary([], q) }}" + ips: "{{ sec | union([ipv4.address]) }}" + when: + - conres.rc == 0 +# - eth.ipv4 is defined + +- name: "destroy connection '{{ conres.stdout }}' if ip does not match" + command: "nmcli connection delete {{ conres.stdout | quote }}" + register: delres + when: + - conres.rc == 0 + - force | default(false) + - not (alias | default(false)) + - not ip_present + +- name: "configure storage network interface '{{ iface }}' to '{{ cidr }}'" + command: "nmcli connection add type infiniband ifname {{ iface | quote }} con-name {{ name }} ip4 {{ cidr }}" + when: + - (conres.rc != 0) or (not (delres | skipped)) + - (conres.rc != 0) or (not (alias | default(false))) + +- name: "add ip alias '{{ cidr }}' to connection '{{ conres.stdout }}' using interface '{{ iface }}'" + command: "nmcli connection modify {{ conres.stdout | quote }} +ipv4.address {{ cidr }}" + register: alres + when: + - alias | default(false) + - conres.rc == 0 + - not ip_present + + +- name: "add ip alias '{{ cidr }}' to network interface '{{ iface }}'" + command: "nmcli connection up {{ conres.stdout | quote }}" + register: alres + when: + - not(alres | skipped) + - alres | succeeded + - not ip_present |