summaryrefslogtreecommitdiffstats
path: root/roles/ands_facts
diff options
context:
space:
mode:
authorSuren A. Chilingaryan <csa@suren.me>2018-03-13 05:01:30 +0100
committerSuren A. Chilingaryan <csa@suren.me>2018-03-13 05:01:30 +0100
commit006f333828db373435daa15483d2ab753048f62a (patch)
tree4ae2bedeeb46e69893ee28f96b7d2d48d37549dc /roles/ands_facts
parent0db2995395d28caf4676ab566085b7c66130b629 (diff)
downloadands-006f333828db373435daa15483d2ab753048f62a.tar.gz
ands-006f333828db373435daa15483d2ab753048f62a.tar.bz2
ands-006f333828db373435daa15483d2ab753048f62a.tar.xz
ands-006f333828db373435daa15483d2ab753048f62a.zip
Production
Diffstat (limited to 'roles/ands_facts')
-rw-r--r--roles/ands_facts/defaults/main.yml6
-rw-r--r--roles/ands_facts/tasks/find_interface_by_net.yml17
-rw-r--r--roles/ands_facts/tasks/network.yml33
3 files changed, 44 insertions, 12 deletions
diff --git a/roles/ands_facts/defaults/main.yml b/roles/ands_facts/defaults/main.yml
index c74984e..5feb354 100644
--- a/roles/ands_facts/defaults/main.yml
+++ b/roles/ands_facts/defaults/main.yml
@@ -25,7 +25,9 @@ ands_cluster_domain: "{{ ansible_domain }}"
ands_inner_domain: "{{ ands_cluster_domain }}"
ands_default_ip: "{{ ansible_default_ipv4.address }}"
+ands_default_cidr: "{{ ansible_default_ipv4.address ~ '/' ~ ( ansible_default_ipv4.netmask | ipaddr('prefix') ) }}"
ands_openshift_default_ip: "{{ ands_resolve_public_ip | default(false) | ternary(ands_default_ip, ands_none) }}"
+ands_openshift_default_cidr: "{{ ands_resolve_public_ip | default(false) | ternary(ands_default_cidr, ands_none) }}"
ands_openshift_default_hostname: "{{ (ands_hostname_template is defined) | ternary(ands_hostname_template ~ ands_host_id, ansible_hostname) }}"
ands_inner_lb: true
@@ -33,5 +35,5 @@ ands_use_inner_lb: false
ands_inner_lb_id: 254
ands_inner_lb_hostname: 'ands-lb'
-#ands_openshift_inner_interface:
-#ands_openshift_public_interface:
+#ands_inner_interface:
+#ands_public_interface:
diff --git a/roles/ands_facts/tasks/find_interface_by_net.yml b/roles/ands_facts/tasks/find_interface_by_net.yml
new file mode 100644
index 0000000..ad44578
--- /dev/null
+++ b/roles/ands_facts/tasks/find_interface_by_net.yml
@@ -0,0 +1,17 @@
+- name: "Looking for interface holding {{ net }}"
+ set_fact:
+ "{{ var }}": "{{ eth['device'] }}"
+ vars:
+ eth: "{{ hostvars[inventory_hostname]['ansible_' + item] | default({}) }}"
+ ipv4: "{{ eth['ipv4'] | default({}) }}"
+ q: "{{ eth | json_query('ipv4_secondaries[*].network') }}"
+ sec: "{{ ((q == ands_none) or (q == '')) | ternary([], q) }}"
+ nets: "{{ sec | union([ipv4.network]) }}"
+ when:
+ - eth['type'] is defined
+ - eth['ipv4'] is defined
+ - eth['device'] is defined
+ - eth['type'] == 'ether'
+ - net | ipaddr('network') in nets
+ with_items:
+ - "{{ hostvars[inventory_hostname]['ansible_interfaces'] }}"
diff --git a/roles/ands_facts/tasks/network.yml b/roles/ands_facts/tasks/network.yml
index 808d7b6..1acafc1 100644
--- a/roles/ands_facts/tasks/network.yml
+++ b/roles/ands_facts/tasks/network.yml
@@ -12,10 +12,13 @@
ands_use_inner_lb: "{{ ands_use_inner_lb }}"
ands_inner_lb_ip: "{{ ands_openshift_network | ipaddr(ands_inner_lb_id) | ipaddr('address') }}"
ands_inner_lb_hostname: "{{ ands_inner_lb_hostname }}"
+ ands_openshift_cidr: "{{ ands_openshift_network | ipaddr(ands_host_id) }}"
ands_openshift_ip: "{{ ands_openshift_network | ipaddr(ands_host_id) | ipaddr('address') }}"
ands_openshift_hostname: "{{ ands_openshift_hostname | default(ands_openshift_default_hostname) }}"
+ ands_openshift_public_cidr: "{{ (ands_openshift_public_network is defined) | ternary( ands_openshift_public_network | ipaddr(ands_host_id), ands_openshift_default_cidr) }}"
ands_openshift_public_ip: "{{ (ands_openshift_public_network is defined) | ternary( ands_openshift_public_network | ipaddr(ands_host_id) | ipaddr('address'), ands_openshift_default_ip) }}"
ands_openshift_public_hostname: "{{ ands_openshift_public_hostname | default(ands_openshift_default_hostname) }}"
+ ands_storage_cidr: "{{ ands_storage_network | default(ands_openshift_network) | ipaddr(ands_host_id) }}"
ands_storage_ip: "{{ ands_storage_network | default(ands_openshift_network) | ipaddr(ands_host_id) | ipaddr('address') }}"
ands_hostname_storage: "ands_storage{{ ands_host_id }}"
ands_hostname_openshift: "ands_openshift{{ ands_host_id }}"
@@ -33,27 +36,37 @@
- name: "Detect inner network interface"
include_tasks: "find_interface_by_ip.yml"
vars:
- var: "ands_openshift_inner_interface"
+ var: "ands_inner_interface"
ip: "{{ ands_openshift_ip }}"
when:
- - ands_openshift_inner_interface is not defined
+ - ands_inner_interface is not defined
-- name: "Detect public network interface"
+- name: "Detect public network interface (using public ip)"
include_tasks: "find_interface_by_ip.yml"
vars:
- var: "ands_openshift_public_interface"
+ var: "ands_public_interface"
ip: "{{ (ands_openshift_public_ip == ands_none) | ternary(ands_default_ip, ands_openshift_public_ip) }}"
when:
- - ands_openshift_public_interface is not defined
+ - ands_public_interface is not defined
-- name: Set ipfailover interface
- set_fact:
- ands_ipfailover_interface: "{{ ands_openshift_public_interface }}"
- when: ands_ipfailover_interface is not defined
+- name: "Detect public network interface (using global network)"
+ include_tasks: "find_interface_by_net.yml"
+ vars:
+ var: "ands_public_interface"
+ net: "{{ ands_global_network }}"
+ when:
+ - ands_public_interface is not defined
+ - ands_global_network is defined
- name: Set ipfailover inner interface
set_fact:
- ands_ipfailover_inner_interface: "{{ ands_openshift_inner_interface }}"
+ ands_ipfailover_inner_interface: "{{ ands_inner_interface }}"
when: ands_ipfailover_inner_interface is not defined
+- name: Set ipfailover interface
+ set_fact:
+ ands_ipfailover_interface: "{{ ands_public_interface }}"
+ when: ands_ipfailover_interface is not defined
+
+
#- debug: msg="{{ hostvars }}"