From 3c20e3607ec1d4ad488c532df5d87ecb8f1e20ce Mon Sep 17 00:00:00 2001 From: Dmitriy Rabotyagov Date: Tue, 7 Dec 2021 20:17:18 +0200 Subject: [PATCH] Improve defining horizon_lib_dir Instead of hardcoding lib directory for distro installs, we can retrieve it dynamically based on the horizon.__file__ output Change-Id: I8e87f9a9945b7526c90ca8c4dc09e43a86ab62e0 Closes-Bug: #1950798 --- defaults/main.yml | 3 +- tasks/horizon_install.yml | 2 +- tasks/horizon_install_source.yml | 117 -------------------------- tasks/horizon_post_install.yml | 31 ++++++- tasks/horizon_post_install_source.yml | 85 +++++++++++++++++++ tasks/horizon_pre_install.yml | 13 +++ templates/horizon-manage.py.j2 | 2 +- vars/debian.yml | 3 - vars/distro_install.yml | 3 - vars/main.yml | 3 + vars/redhat.yml | 3 - vars/source_install.yml | 6 -- 12 files changed, 132 insertions(+), 139 deletions(-) create mode 100644 tasks/horizon_post_install_source.yml diff --git a/defaults/main.yml b/defaults/main.yml index 5a9cb4b7..1c2dab8c 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -144,7 +144,8 @@ horizon_allowed_hosts: - '*' ## Installation directories -horizon_lib_dir: "{{ _horizon_lib_dir }}" +# When horizon_lib_dir is not defined, it will be detected automatically +#horizon_lib_dir: "" horizon_lib_wsgi_file: "{{ horizon_lib_dir }}/openstack_dashboard/wsgi.py" horizon_endpoint_type: internalURL diff --git a/tasks/horizon_install.yml b/tasks/horizon_install.yml index 5beb5fde..3367ef44 100644 --- a/tasks/horizon_install.yml +++ b/tasks/horizon_install.yml @@ -40,5 +40,5 @@ - Restart apache2 - name: Install horizon packages from PIP - import_tasks: horizon_install_source.yml + include_tasks: horizon_install_source.yml when: horizon_install_method == 'source' diff --git a/tasks/horizon_install_source.yml b/tasks/horizon_install_source.yml index d0a2e67f..90d39f00 100644 --- a/tasks/horizon_install_source.yml +++ b/tasks/horizon_install_source.yml @@ -13,28 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Create horizon dir - file: - path: "{{ item.path }}" - state: directory - owner: "{{ item.owner|default(horizon_system_user_name) }}" - group: "{{ item.group|default(horizon_system_group_name) }}" - mode: "{{ item.mode|default('0755') }}" - with_items: - - { path: "/etc/pki/tls/certs", owner: "root", group: "root" } - - { path: "/etc/pki/tls/private", owner: "root", group: "root" } - when: ansible_facts['pkg_mgr'] == 'dnf' - -- name: Create system links - file: - src: "{{ item.src }}" - dest: "{{ item.dest }}" - state: "link" - with_items: - - { src: "/etc/pki/tls/certs", dest: "/etc/ssl/certs" } - - { src: "/etc/pki/tls/private", dest: "/etc/ssl/private" } - when: ansible_facts['pkg_mgr'] == 'dnf' - # NOTE(jrosser) # horizon appears in u-c as is it used as a library for the horizon plugins # the new pip resolver will fail to install horizon if two contradictory @@ -82,98 +60,3 @@ - section: "horizon" option: "venv_tag" value: "{{ horizon_venv_tag }}" - -- name: Find the venv's python version - find: - paths: "{{ horizon_bin | dirname }}/lib/" - patterns: "python*" - file_type: directory - recurse: no - register: _horizon_python_venv_details - tags: - - horizon-config - -- name: Set python lib dir fact - set_fact: - horizon_lib_dir: "{{ _horizon_python_venv_details.files[0].path }}/dist-packages" - tags: - - horizon-config - -- name: Create horizon link for venv - file: - src: "{{ horizon_lib_dir | dirname }}/site-packages" - dest: "{{ horizon_lib_dir }}" - owner: "{{ horizon_system_user_name }}" - group: "{{ horizon_system_group_name }}" - state: "link" - -- name: Create static horizon dir - file: - path: "{{ item.path }}" - state: "directory" - owner: "{{ item.owner|default(horizon_system_user_name) }}" - group: "{{ item.group|default(horizon_system_group_name) }}" - with_items: - - { path: "{{ horizon_lib_dir }}/static", mode: "2755" } - - { path: "{{ horizon_lib_dir }}/openstack_dashboard", mode: "2755" } - - { path: "{{ horizon_lib_dir }}/openstack_dashboard/local", mode: "2755" } - - { path: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled", mode: "2755" } - -- name: Registering dashboards - find: - paths: "{{ horizon_lib_dir }}" - patterns: "^.*(dashboard|ui)$" - file_type: directory - use_regex: yes - excludes: "openstack_dashboard" - recurse: no - register: found_dashboards - -- name: Registering panels - find: - paths: |- - {% set dashboard_path = [] %} - {% for dashboard in found_dashboards.files %} - {% for path in _dashboard_panels_location %} - {% set _ = dashboard_path.append(dashboard.path + path) %} - {% endfor %} - {% endfor %} - {{ dashboard_path }} - patterns: ["^_[0-9]{2,4}_.*.py$"] - file_type: file - use_regex: yes - register: found_panels - -- name: Registering policy files - find: - paths: |- - {% set policy_path = [] %} - {% for dashboard in found_dashboards.files %} - {% for path in _dashboard_panels_location %} - {% set _ = policy_path.append(dashboard.path + path) %} - {% endfor %} - {% endfor %} - {{ policy_path }} - patterns: ["^.*_policy.(json|yaml)$"] - file_type: file - use_regex: yes - register: found_policy - -- name: Link policy files - file: - src: "{{ item.path }}" - dest: "{{ horizon_lib_dir }}/openstack_dashboard/conf/{{ item.path|basename }}" - state: link - with_items: "{{ found_policy.files }}" - notify: - - Compile messages - -- name: Enable project panels - file: - src: "{{ item.path }}" - path: "{{ horizon_dashboard_panel_dir }}/{{ item.path|basename }}" - state: link - with_items: "{{ found_panels.files }}" - notify: - - Compile messages - - Restart apache2 diff --git a/tasks/horizon_post_install.yml b/tasks/horizon_post_install.yml index 7be8e23b..c71f8ab2 100644 --- a/tasks/horizon_post_install.yml +++ b/tasks/horizon_post_install.yml @@ -13,6 +13,23 @@ # See the License for the specific language governing permissions and # limitations under the License. +- name: Define horizon_lib_dir when it's not set + when: horizon_lib_dir is not defined + block: + - name: Find the venv's python version + command: "{{ horizon_bin }}/{{ horizon_venv_python_executable }} -c 'import horizon; print(horizon.__file__)'" + changed_when: false + register: _horizon_python_venv_details + + - name: Set python lib dir fact + set_fact: + horizon_lib_dir: "{{ _horizon_python_venv_details.stdout | dirname | dirname }}" + +- name: Configure source-installed dashboards + include_tasks: horizon_post_install_source.yml + when: horizon_install_method == 'source' + +# NOTE(noonedeadpunk): change of permission is required for collectstatic and compilemessages - name: Ensure horizon dirs are accessible by user file: path: "{{ item.path }}" @@ -36,10 +53,16 @@ group: "{{ horizon_system_group_name }}" mode: "{{ item.mode }}" with_items: - - { src: "horizon_local_settings.py.j2", dest: "/etc/horizon/local_settings.py", owner: "root", mode: "0640", always_install: True } - - { src: "horizon-manage.py.j2", dest: "{{ horizon_bin }}/horizon-manage.py", mode: "0755", always_install: "{{ (horizon_install_method == 'source') }}" } - - { src: "80_admin_default_panel.py.j2", dest: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled/_80_admin_default_panel.py", mode: "0755", always_install: True } - when: item.always_install + - src: "horizon_local_settings.py.j2" + dest: "/etc/horizon/local_settings.py" + owner: "root" + mode: "0640" + - src: "horizon-manage.py.j2" + dest: "{{ horizon_bin }}/horizon-manage.py" + mode: "0755" + - src: "80_admin_default_panel.py.j2" + dest: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled/_80_admin_default_panel.py" + mode: "0755" notify: Restart apache2 - name: Retrieve horizon policy files diff --git a/tasks/horizon_post_install_source.yml b/tasks/horizon_post_install_source.yml new file mode 100644 index 00000000..b4e419b2 --- /dev/null +++ b/tasks/horizon_post_install_source.yml @@ -0,0 +1,85 @@ +--- +# Copyright 2021, City Network International AB +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +- name: Create static horizon dir + file: + path: "{{ item.path }}" + state: "directory" + owner: "{{ item.owner|default(horizon_system_user_name) }}" + group: "{{ item.group|default(horizon_system_group_name) }}" + with_items: + - { path: "{{ horizon_lib_dir }}/static", mode: "2755" } + - { path: "{{ horizon_lib_dir }}/openstack_dashboard", mode: "2755" } + - { path: "{{ horizon_lib_dir }}/openstack_dashboard/local", mode: "2755" } + - { path: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled", mode: "2755" } + +- name: Registering dashboards + find: + paths: "{{ horizon_lib_dir }}" + patterns: "^.*(dashboard|ui)$" + file_type: directory + use_regex: yes + excludes: "openstack_dashboard" + recurse: no + register: found_dashboards + +- name: Registering panels + find: + paths: |- + {% set dashboard_path = [] %} + {% for dashboard in found_dashboards.files %} + {% for path in _dashboard_panels_location %} + {% set _ = dashboard_path.append(dashboard.path + path) %} + {% endfor %} + {% endfor %} + {{ dashboard_path }} + patterns: ["^_[0-9]{2,4}_.*.py$"] + file_type: file + use_regex: yes + register: found_panels + +- name: Registering policy files + find: + paths: |- + {% set policy_path = [] %} + {% for dashboard in found_dashboards.files %} + {% for path in _dashboard_panels_location %} + {% set _ = policy_path.append(dashboard.path + path) %} + {% endfor %} + {% endfor %} + {{ policy_path }} + patterns: ["^.*_policy.(json|yaml)$"] + file_type: file + use_regex: yes + register: found_policy + +- name: Link policy files + file: + src: "{{ item.path }}" + dest: "{{ horizon_lib_dir }}/openstack_dashboard/conf/{{ item.path|basename }}" + state: link + with_items: "{{ found_policy.files }}" + notify: + - Compile messages + +- name: Enable project panels + file: + src: "{{ item.path }}" + path: "{{ horizon_dashboard_panel_dir }}/{{ item.path|basename }}" + state: link + with_items: "{{ found_panels.files }}" + notify: + - Compile messages + - Restart apache2 diff --git a/tasks/horizon_pre_install.yml b/tasks/horizon_pre_install.yml index 85a0afd7..52435b03 100644 --- a/tasks/horizon_pre_install.yml +++ b/tasks/horizon_pre_install.yml @@ -36,7 +36,20 @@ owner: "{{ item.owner|default(horizon_system_user_name) }}" group: "{{ item.group|default(horizon_system_group_name) }}" mode: "{{ item.mode|default('0755') }}" + when: item.condition | default(True) with_items: - { path: "/openstack/venvs", mode: "0755", owner: "root", group: "root" } - { path: "/etc/horizon", mode: "2750" } - { path: "{{ horizon_system_user_home }}", mode: "2755" } + - { path: "/etc/pki/tls/certs", owner: "root", group: "root", condition: "{{ (ansible_facts['pkg_mgr'] == 'dnf') }}" } + - { path: "/etc/pki/tls/private", owner: "root", group: "root", condition: "{{ (ansible_facts['pkg_mgr'] == 'dnf') }}" } + +- name: Create system links + file: + src: "{{ item.src }}" + dest: "{{ item.dest }}" + state: "link" + with_items: + - { src: "/etc/pki/tls/certs", dest: "/etc/ssl/certs" } + - { src: "/etc/pki/tls/private", dest: "/etc/ssl/private" } + when: ansible_facts['pkg_mgr'] == 'dnf' diff --git a/templates/horizon-manage.py.j2 b/templates/horizon-manage.py.j2 index 53e328b4..a9a29240 100644 --- a/templates/horizon-manage.py.j2 +++ b/templates/horizon-manage.py.j2 @@ -1,4 +1,4 @@ -#!{{ horizon_bin }}/python +#!{{ horizon_bin }}/{{ horizon_venv_python_executable }} # Licensed under the Apache License, Version 2.0 (the "License"); you may # not use this file except in compliance with the License. You may obtain diff --git a/vars/debian.yml b/vars/debian.yml index 5ce0358f..f2bd1464 100644 --- a/vars/debian.yml +++ b/vars/debian.yml @@ -64,6 +64,3 @@ horizon_apache_modules: state: "present" - name: "headers" state: "present" - -_horizon_lib_dir: "/usr/share/openstack-dashboard" -horizon_dashboard_panel_dir: "{{ _horizon_lib_dir }}/openstack_dashboard/local/enabled" diff --git a/vars/distro_install.yml b/vars/distro_install.yml index 8ba70940..ffdd3bb2 100644 --- a/vars/distro_install.yml +++ b/vars/distro_install.yml @@ -16,6 +16,3 @@ horizon_package_list: "{{ horizon_distro_packages + horizon_service_distro_packages }}" _horizon_bin: "/usr/bin" -horizon_manage: >- - {{ ((ansible_facts['os_family'] | lower) == 'debian') | ternary('/usr/bin/python3', ansible_facts['python']['executable']) }} - {{ horizon_lib_dir }}/manage.py diff --git a/vars/main.yml b/vars/main.yml index beb2e49c..aeeb6c2b 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -45,3 +45,6 @@ _horizon_translations_pull: branch: "{{ horizon_translations_project_version }}" enabled: True module: trove_dashboard + +horizon_dashboard_panel_dir: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled" +horizon_manage: "{{ horizon_bin }}/horizon-manage.py" diff --git a/vars/redhat.yml b/vars/redhat.yml index 25a073d7..fa4b15bb 100644 --- a/vars/redhat.yml +++ b/vars/redhat.yml @@ -55,6 +55,3 @@ horizon_apache_default_sites: - "/etc/httpd/conf.d/userdir.conf" - "/etc/httpd/conf.d/welcome.conf" - "/etc/httpd/conf.d/ssl.conf" - -_horizon_lib_dir: "/usr/share/openstack-dashboard" -horizon_dashboard_panel_dir: "{{ _horizon_lib_dir }}/openstack_dashboard/local/enabled" diff --git a/vars/source_install.yml b/vars/source_install.yml index d1640bba..4235832d 100644 --- a/vars/source_install.yml +++ b/vars/source_install.yml @@ -16,12 +16,6 @@ horizon_package_list: "{{ horizon_distro_packages }}" _horizon_bin: "/openstack/venvs/horizon-{{ horizon_venv_tag }}/bin" -#NOTE(jrosser) for compatibility with py2 and py3 we detect the location of -#this dir during the source install and set a fact(horizon_lib_dir) -#_horizon_lib_dir: "{{ _horizon_bin | dirname }}/lib/python2.7/dist-packages" -horizon_dashboard_panel_dir: "{{ horizon_lib_dir }}/openstack_dashboard/local/enabled" - -horizon_manage: "{{ _horizon_bin }}/horizon-manage.py" _dashboard_panels_location: - "/enabled" - "/conf"