From 65fa37fb84ba9dbeaa421023b06b8a2cbfb25f79 Mon Sep 17 00:00:00 2001 From: Jianghua Wang Date: Fri, 9 Feb 2018 07:59:15 +0000 Subject: [PATCH] XenAPI: centralize the facts files When bootstrap compute hosts for XenAPI, it will generate a facts file for each compute node. It contains some XenAPI specific variables for both the compute host and the XenServer where the compute host run on. This commit is to fetch the facts file into deployment host and put it under a centralized directory - each compute host will have a separate sub-dir which is named with its *inventory_hostname*. In this way, the following tasks can use proper variable from the proper facts file which exactly belongs to the host they running on. Change-Id: I68d1a2d098d38c8e6bf4db76cdaf1f0465831822 blueprint: xenserver-support --- ansible/group_vars/all.yml | 3 ++- ansible/roles/neutron/tasks/config.yml | 2 +- ansible/roles/nova/tasks/bootstrap_xenapi.yml | 20 +++++++++++++++++-- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/ansible/group_vars/all.yml b/ansible/group_vars/all.yml index f547cec0d7..b5ccbb3d5e 100644 --- a/ansible/group_vars/all.yml +++ b/ansible/group_vars/all.yml @@ -736,7 +736,8 @@ xenserver_himn_ip: "169.254.0.1" xenserver_username: "root" xenserver_connect_protocol: "https" # File used to save XenAPI's facts variables formatted as json. -xenapi_facts_file: "/etc/kolla/xenapi.json" +xenapi_facts_root: "/etc/kolla/xenapi/" +xenapi_facts_file: "facts.json" ############################################# # MariaDB component-specific database details diff --git a/ansible/roles/neutron/tasks/config.yml b/ansible/roles/neutron/tasks/config.yml index 596eea1913..c7e6a54495 100644 --- a/ansible/roles/neutron/tasks/config.yml +++ b/ansible/roles/neutron/tasks/config.yml @@ -149,7 +149,7 @@ service_name: "{{ item.key }}" services_need_ml2_conf_ini: - "neutron-openvswitch-agent-xenapi" - os_xenapi_variables: "{{ lookup('file', xenapi_facts_file) | from_json }}" + os_xenapi_variables: "{{ lookup('file', xenapi_facts_root + '/' + inventory_hostname + '/' + xenapi_facts_file) | from_json }}" merge_configs: sources: - "{{ role_path }}/templates/ml2_conf.ini.j2" diff --git a/ansible/roles/nova/tasks/bootstrap_xenapi.yml b/ansible/roles/nova/tasks/bootstrap_xenapi.yml index 7abb543d48..7673463e92 100644 --- a/ansible/roles/nova/tasks/bootstrap_xenapi.yml +++ b/ansible/roles/nova/tasks/bootstrap_xenapi.yml @@ -4,6 +4,22 @@ state: present become: True -- name: Bootstrap XenAPI compute node - command: xenapi_bootstrap -i {{ xenserver_himn_ip }} -u {{ xenserver_username }} -p {{ xenserver_password }} -f {{ xenapi_facts_file }} +- name: Ensure XenAPI root path + file: + path: "{{ xenapi_facts_root }}" + state: directory + mode: "0770" + become: True + +- name: Bootstrap XenAPI compute node + vars: + xenapi_facts_path: "{{ xenapi_facts_root + '/' + xenapi_facts_file }}" + command: xenapi_bootstrap -i {{ xenserver_himn_ip }} -u {{ xenserver_username }} -p {{ xenserver_password }} -f {{ xenapi_facts_path }} + become: True + +- name: Fetching XenAPI facts file + fetch: + src: "{{ xenapi_facts_root + '/' + xenapi_facts_file }}" + dest: "{{ xenapi_facts_root + '/' + inventory_hostname + '/' }}" + flat: yes become: True