From 0bcea6eaf24b796ba6b2658c213c8bc24783d498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9na=C3=AFc=20Huard?= Date: Wed, 12 Aug 2015 17:48:33 +0200 Subject: Add the sub-host-type tag to the libvirt VMs --- playbooks/libvirt/openshift-cluster/tasks/launch_instances.yml | 2 +- playbooks/libvirt/openshift-cluster/templates/domain.xml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/playbooks/libvirt/openshift-cluster/tasks/launch_instances.yml b/playbooks/libvirt/openshift-cluster/tasks/launch_instances.yml index 4b91c6da8..4825207c9 100644 --- a/playbooks/libvirt/openshift-cluster/tasks/launch_instances.yml +++ b/playbooks/libvirt/openshift-cluster/tasks/launch_instances.yml @@ -81,7 +81,7 @@ ansible_ssh_host: '{{ item.1 }}' ansible_ssh_user: "{{ deployment_vars[deployment_type].ssh_user }}" ansible_sudo: "{{ deployment_vars[deployment_type].sudo }}" - groups: 'tag_env-{{ cluster }}, tag_host-type-{{ type }}, tag_env-host-type-{{ cluster }}-openshift-{{ type }}' + groups: 'tag_env-{{ cluster }}, tag_host-type-{{ type }}, tag_env-host-type-{{ cluster }}-openshift-{{ type }}, tag_sub-host-type-{{ g_sub_host_type }}' with_together: - instances - ips diff --git a/playbooks/libvirt/openshift-cluster/templates/domain.xml b/playbooks/libvirt/openshift-cluster/templates/domain.xml index df200e374..870bcf2a6 100644 --- a/playbooks/libvirt/openshift-cluster/templates/domain.xml +++ b/playbooks/libvirt/openshift-cluster/templates/domain.xml @@ -6,6 +6,7 @@ env-{{ cluster }} env-host-type-{{ cluster }}-openshift-{{ type }} host-type-{{ type }} + sub-host-type-{{ g_sub_host_type }} 1 -- cgit v1.2.3 From 332aa8c8219ba99510090ce2412326780ad9ce74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9na=C3=AFc=20Huard?= Date: Thu, 13 Aug 2015 14:45:25 +0200 Subject: Better structure the output of the list playbook The list playbook listed the IPs of the VMs without logging their role like: TASK: [debug ] ************************************************************ ok: [10.64.109.37] => { "msg": "public:10.64.109.37 private:192.168.165.5" } ok: [10.64.109.47] => { "msg": "public:10.64.109.47 private:192.168.165.6" } ok: [10.64.109.36] => { "msg": "public:10.64.109.36 private:192.168.165.4" } ok: [10.64.109.215] => { "msg": "public:10.64.109.215 private:192.168.165.2" } The list playbook now prints the information in a more structured way with a list of masters, a list of nodes and the subtype of the nodes like: TASK: [debug ] ************************************************************ ok: [localhost] => { "msg": { "lenaicnewlist": { "master": [ { "name": "10.64.109.215", "private IP": "192.168.165.2", "public IP": "10.64.109.215", "subtype": "default" } ], "node": [ { "name": "10.64.109.47", "private IP": "192.168.165.6", "public IP": "10.64.109.47", "subtype": "compute" }, { "name": "10.64.109.37", "private IP": "192.168.165.5", "public IP": "10.64.109.37", "subtype": "compute" }, { "name": "10.64.109.36", "private IP": "192.168.165.4", "public IP": "10.64.109.36", "subtype": "infra" } ] } } } --- filter_plugins/oo_filters.py | 57 +++++++++++++++++++++++++- playbooks/libvirt/openshift-cluster/list.yml | 8 +++- playbooks/openstack/openshift-cluster/list.yml | 8 +++- 3 files changed, 70 insertions(+), 3 deletions(-) diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py index 9a17913c4..cf141d4f8 100644 --- a/filter_plugins/oo_filters.py +++ b/filter_plugins/oo_filters.py @@ -401,6 +401,60 @@ class FilterModule(object): "certificate names in host inventory")) return certificates + @staticmethod + def oo_pretty_print_cluster(data): + ''' Read a subset of hostvars and build a summary of the cluster + in the following layout: + +"c_id": { + "master": [ + { "name": "c_id-master-12345", "public IP": "172.16.0.1", "private IP": "192.168.0.1", "subtype": "default" }] + "node": [ + { "name": "c_id-node-infra-23456", "public IP": "172.16.0.2", "private IP": "192.168.0.2", "subtype": "infra" }, + { "name": "c_id-node-compute-23456", "public IP": "172.16.0.3", "private IP": "192.168.0.3", "subtype": "compute" }, + ... + ]} + ''' + + def _get_tag_value(tags, key): + ''' Extract values of a map implemented as a set. + Ex: tags = { 'tag_foo_value1', 'tag_bar_value2', 'tag_baz_value3' } + key = 'bar' + returns 'value2' + ''' + for tag in tags: + # Skip tag_env-host-type to avoid ambiguity with tag_env + if tag[:17] == 'tag_env-host-type': + continue + if tag[:len(key)+4] == 'tag_' + key: + return tag[len(key)+5:] + raise KeyError(key) + + def _add_host(clusters, + env, + host_type, + host): + ''' Add a new host in the clusters data structure ''' + if env not in clusters: + clusters[env] = {} + if host_type not in clusters[env]: + clusters[env][host_type] = [] + clusters[env][host_type].append(host) + + clusters = {} + for host in data: + try: + _add_host(clusters=clusters, + env=_get_tag_value(host['group_names'], 'env'), + host_type=_get_tag_value(host['group_names'], 'host-type'), + host={'name': host['inventory_hostname'], + 'public IP': host['ansible_ssh_host'], + 'private IP': host['ansible_default_ipv4']['address'], + 'subtype': _get_tag_value(host['group_names'], 'sub-host-type')}) + except KeyError: + pass + return clusters + def filters(self): ''' returns a mapping of filters to methods ''' return { @@ -418,5 +472,6 @@ class FilterModule(object): "oo_filter_list": self.oo_filter_list, "oo_parse_heat_stack_outputs": self.oo_parse_heat_stack_outputs, "oo_parse_certificate_names": self.oo_parse_certificate_names, - "oo_haproxy_backend_masters": self.oo_haproxy_backend_masters + "oo_haproxy_backend_masters": self.oo_haproxy_backend_masters, + "oo_pretty_print_cluster": self.oo_pretty_print_cluster } diff --git a/playbooks/libvirt/openshift-cluster/list.yml b/playbooks/libvirt/openshift-cluster/list.yml index eaedc4d0d..5954bb01e 100644 --- a/playbooks/libvirt/openshift-cluster/list.yml +++ b/playbooks/libvirt/openshift-cluster/list.yml @@ -18,6 +18,12 @@ - name: List Hosts hosts: oo_list_hosts + +- name: List Hosts + hosts: localhost + gather_facts: no + vars_files: + - vars.yml tasks: - debug: - msg: 'public:{{ansible_default_ipv4.address}} private:{{ansible_default_ipv4.address}}' + msg: "{{ hostvars | oo_select_keys(groups[scratch_group] | default([])) | oo_pretty_print_cluster }}" diff --git a/playbooks/openstack/openshift-cluster/list.yml b/playbooks/openstack/openshift-cluster/list.yml index a75e350c7..fa194b072 100644 --- a/playbooks/openstack/openshift-cluster/list.yml +++ b/playbooks/openstack/openshift-cluster/list.yml @@ -19,6 +19,12 @@ - name: List Hosts hosts: oo_list_hosts + +- name: List Hosts + hosts: localhost + gather_facts: no + vars_files: + - vars.yml tasks: - debug: - msg: 'public:{{ansible_ssh_host}} private:{{ansible_default_ipv4.address}}' + msg: "{{ hostvars | oo_select_keys(groups[scratch_group] | default([])) | oo_pretty_print_cluster }}" -- cgit v1.2.3 From 3c560d4a589cb7c7144f25468e0c7d2d0768853d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9na=C3=AFc=20Huard?= Date: Mon, 16 Nov 2015 14:42:45 +0100 Subject: cluster list: break host types by subtype --- filter_plugins/oo_filters.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/filter_plugins/oo_filters.py b/filter_plugins/oo_filters.py index cf141d4f8..2386b5878 100644 --- a/filter_plugins/oo_filters.py +++ b/filter_plugins/oo_filters.py @@ -433,13 +433,16 @@ class FilterModule(object): def _add_host(clusters, env, host_type, + sub_host_type, host): ''' Add a new host in the clusters data structure ''' if env not in clusters: clusters[env] = {} if host_type not in clusters[env]: - clusters[env][host_type] = [] - clusters[env][host_type].append(host) + clusters[env][host_type] = {} + if sub_host_type not in clusters[env][host_type]: + clusters[env][host_type][sub_host_type] = [] + clusters[env][host_type][sub_host_type].append(host) clusters = {} for host in data: @@ -447,10 +450,10 @@ class FilterModule(object): _add_host(clusters=clusters, env=_get_tag_value(host['group_names'], 'env'), host_type=_get_tag_value(host['group_names'], 'host-type'), + sub_host_type=_get_tag_value(host['group_names'], 'sub-host-type'), host={'name': host['inventory_hostname'], 'public IP': host['ansible_ssh_host'], - 'private IP': host['ansible_default_ipv4']['address'], - 'subtype': _get_tag_value(host['group_names'], 'sub-host-type')}) + 'private IP': host['ansible_default_ipv4']['address']}) except KeyError: pass return clusters -- cgit v1.2.3