From a7681b96b8321b76b05669ff575a66989d5dc1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fl=C3=A1vio=20Ramalho?= Date: Mon, 13 Feb 2017 12:33:06 -0300 Subject: [PATCH] Role cleanup/update for ocata - Use dictionary for service group mappings, bringing the role into line with the method used in other roles; - Use systemd module instead of shell on the services restart handlers; - Use ansible package module to install distro packages; - Added variables for CentOS. The role should now support CentOS; - Removed extras folder. Change-Id: I5c8430804aacceca01c5821ca2528514033d15f4 (cherry picked from commit 95e4f4877bb5a9be0b2c88f541ef0471d4735dd3) --- defaults/main.yml | 14 ++-- extras/env.d/sahara.yml | 38 ----------- extras/group_vars_sahara.yml | 20 ------ extras/haproxy_sahara.yml | 10 --- extras/os-sahara-install.yml | 64 ------------------- extras/repo-sahara.yml | 5 -- extras/user_secrets_sahara.yml | 3 - handlers/main.yml | 18 ++---- meta/main.yml | 2 +- tasks/main.yml | 5 +- tasks/sahara_init.yml | 28 -------- tasks/sahara_init_common.yml | 7 +- tasks/sahara_init_systemd.yml | 44 ++++++++----- tasks/sahara_install.yml | 25 ++++++-- tasks/sahara_post_install.yml | 6 +- templates/sahara-systemd-init.j2 | 8 +-- templates/sahara-systemd-tempfiles.j2 | 4 -- templates/sahara-systemd-tmpfiles.j2 | 4 ++ tests/inventory | 9 ++- .../redhat-7.yml | 17 ++--- 20 files changed, 93 insertions(+), 238 deletions(-) delete mode 100644 extras/env.d/sahara.yml delete mode 100644 extras/group_vars_sahara.yml delete mode 100644 extras/haproxy_sahara.yml delete mode 100644 extras/os-sahara-install.yml delete mode 100644 extras/repo-sahara.yml delete mode 100644 extras/user_secrets_sahara.yml delete mode 100644 tasks/sahara_init.yml delete mode 100644 templates/sahara-systemd-tempfiles.j2 create mode 100644 templates/sahara-systemd-tmpfiles.j2 rename tasks/sahara_install_apt.yml => vars/redhat-7.yml (64%) diff --git a/defaults/main.yml b/defaults/main.yml index f513d5f..704b707 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -75,8 +75,6 @@ sahara_galera_user: sahara sahara_role_name: admin sahara_api_bind_address: 0.0.0.0 sahara_api_service_port: 8386 -sahara_api_program_name: sahara-api -sahara_engine_program_name: sahara-engine ## Service Type and Data sahara_service_region: RegionOne @@ -152,7 +150,7 @@ sahara_policy_dirs: policy.d sahara_service_in_ldap: False # Sahara packages that must be installed before anything else -sahara_required_pip_packages: +sahara_requires_pip_packages: - virtualenv - virtualenv-tools - python-keystoneclient # Keystoneclient needed to OSA keystone lib @@ -170,9 +168,13 @@ sahara_pip_packages: - warlock ## Service Names -sahara_service_names: - - "sahara-api" - - "sahara-engine" +sahara_services: + sahara-api: + group: sahara_api + service_name: sahara-api + sahara-engine: + group: sahara_engine + service_name: sahara-engine # This variable is used by the repo_build process to determine # which host group to check for members of before building the diff --git a/extras/env.d/sahara.yml b/extras/env.d/sahara.yml deleted file mode 100644 index 3b4c9af..0000000 --- a/extras/env.d/sahara.yml +++ /dev/null @@ -1,38 +0,0 @@ ---- -# 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. - -component_skel: - sahara_api: - belongs_to: - - sahara_all - sahara_engine: - belongs_to: - - sahara_all - -container_skel: - sahara_container: - belongs_to: - - sahara-infra_containers - contains: - - sahara_api - - sahara_engine - properties: - service_name: sahara - -physical_skel: - sahara-infra_containers: - belongs_to: - - all_containers - sahara-infra_hosts: - belongs_to: - - hosts diff --git a/extras/group_vars_sahara.yml b/extras/group_vars_sahara.yml deleted file mode 100644 index a5814af..0000000 --- a/extras/group_vars_sahara.yml +++ /dev/null @@ -1,20 +0,0 @@ ---- -# 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. - -sahara_service_region: "{{ service_region }}" -sahara_service_in_ldap: "{{ service_ldap_backend_enabled }}" - -sahara_galera_address: "{{ galera_address }}" - -# If there are any Ceilometer hosts in the environment, then enable its usage -sahara_ceilometer_enabled: "{{ (groups['ceilometer_all'] is defined) and (groups['ceilometer_all'] | length > 0) }}" diff --git a/extras/haproxy_sahara.yml b/extras/haproxy_sahara.yml deleted file mode 100644 index 17e818d..0000000 --- a/extras/haproxy_sahara.yml +++ /dev/null @@ -1,10 +0,0 @@ -haproxy_service_configs: - - service: - haproxy_service_name: sahara_api - haproxy_backend_nodes: "{{ groups['sahara_api'] | default([]) }}" - haproxy_ssl: "{{ haproxy_ssl }}" - haproxy_balance_alg: source - haproxy_port: 8386 - haproxy_balance_type: http - haproxy_backend_options: - - "httpchk /healthcheck" diff --git a/extras/os-sahara-install.yml b/extras/os-sahara-install.yml deleted file mode 100644 index acac52b..0000000 --- a/extras/os-sahara-install.yml +++ /dev/null @@ -1,64 +0,0 @@ ---- -# 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: Install sahara server - hosts: sahara_all - gather_facts: "{{ gather_facts | default(True) }}" - max_fail_percentage: 20 - user: root - pre_tasks: - - include: common-tasks/rabbitmq-servers-sort.yml - vars: - sort_group_name: "sahara_all" - - include: common-tasks/os-lxc-container-setup.yml - - include: common-tasks/rabbitmq-vhost-user.yml - vars: - user: "{{ sahara_rabbitmq_userid }}" - password: "{{ sahara_rabbitmq_password }}" - vhost: "{{ sahara_rabbitmq_vhost }}" - when: - - inventory_hostname == groups['sahara_all'][0] - - groups['rabbitmq_all'] | length > 0 - - include: common-tasks/os-log-dir-setup.yml - vars: - log_dirs: - - src: "/openstack/log/{{ inventory_hostname }}-sahara" - dest: "/var/log/sahara" - - include: common-tasks/mysql-db-user.yml - vars: - user_name: "{{ sahara_galera_user }}" - password: "{{ sahara_container_mysql_password }}" - login_host: "{{ sahara_galera_address }}" - db_name: "{{ sahara_galera_database }}" - when: inventory_hostname == groups['sahara_all'][0] - - include: common-tasks/package-cache-proxy.yml - roles: - - role: "os_sahara" - sahara_venv_tag: "{{ openstack_release }}" - sahara_venv_download_url: "{{ openstack_repo_url }}/venvs/{{ openstack_release }}/{{ ansible_distribution | lower }}/sahara-{{ openstack_release }}-{{ ansible_architecture | lower }}.tgz" - tags: - - "os-sahara" - - { role: "openstack_openrc", tags: [ "openstack-openrc" ] } - - role: "rsyslog_client" - rsyslog_client_log_rotate_file: sahara_log_rotate - rsyslog_client_log_dir: "/var/log/sahara" - rsyslog_client_config_name: "99-sahara-rsyslog-client.conf" - tags: - - "sahara-rsyslog-client" - - "rsyslog-client" - - role: "system_crontab_coordination" - tags: - - "system-crontab-coordination" - vars: - is_metal: "{{ properties.is_metal|default(false) }}" - pip_lock_to_internal_repo: "{{ (pip_links | length) >= 1 }}" diff --git a/extras/repo-sahara.yml b/extras/repo-sahara.yml deleted file mode 100644 index 637c895..0000000 --- a/extras/repo-sahara.yml +++ /dev/null @@ -1,5 +0,0 @@ -## Sahara service -sahara_git_repo: https://git.openstack.org/openstack/sahara -sahara_git_install_branch: master -sahara_git_dest: "/opt/sahara_{{ sahara_git_install_branch | replace('/', '_') }}" -sahara_git_project_group: sahara_all diff --git a/extras/user_secrets_sahara.yml b/extras/user_secrets_sahara.yml deleted file mode 100644 index 23438e2..0000000 --- a/extras/user_secrets_sahara.yml +++ /dev/null @@ -1,3 +0,0 @@ -sahara_container_mysql_password: -sahara_rabbitmq_password: -sahara_service_password: diff --git a/handlers/main.yml b/handlers/main.yml index 328e8c9..a3f2ac1 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -11,18 +11,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Restart sahara api - service: - name: "sahara-api" - state: "restarted" - -- name: Restart sahara engine - service: - name: "sahara-engine" - state: "restarted" - - name: Restart sahara services - service: - name: "{{ item }}" + systemd: + name: "{{ item.value.service_name }}" state: "restarted" - with_items: "{{ sahara_service_names }}" + daemon_reload: yes + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] diff --git a/meta/main.yml b/meta/main.yml index 52701df..e23a113 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -4,7 +4,7 @@ galaxy_info: description: Installation and setup of sahara company: LSD/UFCG license: Apache2 - min_ansible_version: 2.0 + min_ansible_version: 2.1 platforms: - name: Ubuntu versions: diff --git a/tasks/main.yml b/tasks/main.yml index 6d291c5..7f685ce 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,7 +15,10 @@ include_vars: "{{ item }}" with_first_found: - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" + - "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_major_version | lower }}.yml" - "{{ ansible_distribution | lower }}.yml" + - "{{ ansible_os_family | lower }}-{{ ansible_distribution_version.split('.')[0] }}.yml" - "{{ ansible_os_family | lower }}.yml" tags: - always @@ -32,7 +35,7 @@ tags: - sahara-config -- include: sahara_init.yml +- include: sahara_init_common.yml tags: - sahara-config diff --git a/tasks/sahara_init.yml b/tasks/sahara_init.yml deleted file mode 100644 index eb5fc83..0000000 --- a/tasks/sahara_init.yml +++ /dev/null @@ -1,28 +0,0 @@ ---- -# 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. - -- include: sahara_init_common.yml - vars: - program_name: "{{ sahara_api_program_name }}" - service_name: "{{ sahara_service_name }}" - system_user: "{{ sahara_system_user_name }}" - system_group: "{{ sahara_system_group_name }}" - service_home: "{{ sahara_system_user_home }}" - -- include: sahara_init_common.yml - vars: - program_name: "{{ sahara_engine_program_name }}" - service_name: "{{ sahara_service_name }}" - system_user: "{{ sahara_system_user_name }}" - system_group: "{{ sahara_system_group_name }}" - service_home: "{{ sahara_system_user_home }}" diff --git a/tasks/sahara_init_common.yml b/tasks/sahara_init_common.yml index ec48adc..59879e0 100644 --- a/tasks/sahara_init_common.yml +++ b/tasks/sahara_init_common.yml @@ -12,13 +12,14 @@ # limitations under the License. - include: sahara_init_systemd.yml - static: no when: - ansible_service_mgr == 'systemd' - name: Load service service: - name: "{{ program_name }}" - enabled: "yes" + name: "{{ item.value.service_name }}" + enabled: "yes" + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] notify: - Restart sahara services diff --git a/tasks/sahara_init_systemd.yml b/tasks/sahara_init_systemd.yml index 906b0a2..bbba821 100644 --- a/tasks/sahara_init_systemd.yml +++ b/tasks/sahara_init_systemd.yml @@ -1,4 +1,3 @@ - --- # Copyright 2016, Rackspace US, Inc. # @@ -16,39 +15,52 @@ - name: Create TEMP run dir file: - path: "/var/run/{{ program_name }}" + path: "/var/run/{{ item.value.service_name }}" state: directory - owner: "{{ system_user }}" - group: "{{ system_group }}" + owner: "{{ sahara_system_user_name }}" + group: "{{ sahara_system_group_name }}" mode: "02755" + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] - name: Create TEMP lock dir file: - path: "/var/lock/{{ program_name }}" + path: "/var/lock/{{ item.value.service_name }}" state: directory - owner: "{{ system_user }}" - group: "{{ system_group }}" + owner: "{{ sahara_system_user_name }}" + group: "{{ sahara_system_group_name }}" mode: "02755" + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] -- name: Create tempfile.d entry +# TODO: +# Remove this in Pike as it only needed to handle upgrades +# from Newton->Newton and Newton->Ocata +- name: Cleanup old tmpfiles.d entry + file: + path: "/etc/tmpfiles.d/{{ item.value.service_name }}.conf" + state: absent + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] + +- name: Create tmpfiles.d entry template: - src: "sahara-systemd-tempfiles.j2" - dest: "/etc/tmpfiles.d/sahara.conf" + src: "sahara-systemd-tmpfiles.j2" + dest: "/etc/tmpfiles.d/{{ item.value.service_name }}.conf" mode: "0644" owner: "root" group: "root" + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] - name: Place the systemd init script template: src: "sahara-systemd-init.j2" - dest: "/etc/systemd/system/{{ program_name }}.service" + dest: "/etc/systemd/system/{{ item.value.service_name }}.service" mode: "0644" owner: "root" group: "root" - register: systemd_init - -- name: Reload the systemd daemon - command: "systemctl daemon-reload" - when: systemd_init | changed + with_dict: "{{ sahara_services }}" + when: inventory_hostname in groups[item.value.group] notify: - Restart sahara services diff --git a/tasks/sahara_install.yml b/tasks/sahara_install.yml index 864d9ec..19da176 100644 --- a/tasks/sahara_install.yml +++ b/tasks/sahara_install.yml @@ -11,9 +11,22 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include: sahara_install_apt.yml - static: no - when: ansible_pkg_mgr == 'apt' +- name: Ensure apt cache is up to date + apt: + update_cache: yes + cache_valid_time: "{{ cache_timeout }}" + when: + - ansible_pkg_mgr == 'apt' + +- name: Install distro packages + package: + name: "{{ item }}" + state: "{{ sahara_package_state }}" + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + with_items: "{{ sahara_distro_packages }}" - name: Create developer mode constraint file copy: @@ -25,10 +38,10 @@ when: - sahara_developer_mode | bool -- name: Install required pip packages +- name: Install requires pip packages pip: - name: "{{ sahara_required_pip_packages }}" - state: present + name: "{{ sahara_requires_pip_packages }}" + state: "{{ sahara_pip_package_state }}" extra_args: >- {{ (pip_install_upper_constraints is defined) | ternary('--constraint ' + pip_install_upper_constraints | default(''),'') }} {{ pip_install_options | default('') }} diff --git a/tasks/sahara_post_install.yml b/tasks/sahara_post_install.yml index 0e65ba1..772fb34 100644 --- a/tasks/sahara_post_install.yml +++ b/tasks/sahara_post_install.yml @@ -40,8 +40,7 @@ config_overrides: "{{ sahara_policy_overrides }}" config_type: "json" notify: - - Restart sahara api - - Restart sahara engine + - Restart sahara services - name: Drop rootwrap filter(s) copy: @@ -52,5 +51,4 @@ with_fileglob: - rootwrap.d/* notify: - - Restart sahara api - - Restart sahara engine + - Restart sahara services diff --git a/templates/sahara-systemd-init.j2 b/templates/sahara-systemd-init.j2 index 1160fd0..64ea8a7 100644 --- a/templates/sahara-systemd-init.j2 +++ b/templates/sahara-systemd-init.j2 @@ -7,13 +7,13 @@ After=network.target [Service] Type=simple -User={{ system_user }} -Group={{ system_group }} +User={{ sahara_system_user_name }} +Group={{ sahara_system_group_name }} {% if program_override is defined %} -ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ program_name }}.log +ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ item.value.service_name }}.log {% else %} -ExecStart={{ sahara_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ program_name }}.log +ExecStart={{ sahara_bin }}/{{ item.value.service_name }} {{ program_config_options|default('') }} --log-file=/var/log/sahara/{{ item.value.service_name }}.log {% endif %} # Give a reasonable amount of time for the server to start up/shut down diff --git a/templates/sahara-systemd-tempfiles.j2 b/templates/sahara-systemd-tempfiles.j2 deleted file mode 100644 index b723d85..0000000 --- a/templates/sahara-systemd-tempfiles.j2 +++ /dev/null @@ -1,4 +0,0 @@ -# {{ ansible_managed }} - -D /var/lock/{{ program_name }} 2755 {{ system_user }} {{ system_group }} -D /var/run/{{ program_name }} 2755 {{ system_user }} {{ system_group }} diff --git a/templates/sahara-systemd-tmpfiles.j2 b/templates/sahara-systemd-tmpfiles.j2 new file mode 100644 index 0000000..f62fd3a --- /dev/null +++ b/templates/sahara-systemd-tmpfiles.j2 @@ -0,0 +1,4 @@ +# {{ ansible_managed }} + +D /var/lock/{{ item.value.service_name }} 2755 {{ sahara_system_user_name }} {{ sahara_system_group_name }} +D /var/run/{{ item.value.service_name }} 2755 {{ sahara_system_user_name }} {{ sahara_system_group_name }} diff --git a/tests/inventory b/tests/inventory index 864414b..bd0964c 100644 --- a/tests/inventory +++ b/tests/inventory @@ -45,5 +45,12 @@ nova_api_os_compute [keystone_all] openstack1 -[sahara_all] +[sahara_api] sahara1 + +[sahara_engine] +sahara1 + +[sahara_all:children] +sahara_api +sahara_engine diff --git a/tasks/sahara_install_apt.yml b/vars/redhat-7.yml similarity index 64% rename from tasks/sahara_install_apt.yml rename to vars/redhat-7.yml index 38446ba..8bed21b 100644 --- a/tasks/sahara_install_apt.yml +++ b/vars/redhat-7.yml @@ -10,14 +10,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -- name: Install apt packages - apt: - pkg: "{{ item }}" - state: "{{ sahara_package_state }}" - update_cache: yes - cache_valid_time: "{{ cache_timeout }}" - register: install_packages - until: install_packages|success - retries: 5 - delay: 2 - with_items: "{{ sahara_distro_packages }}" +sahara_distro_packages: + - cronie + - cronie-anacron + - rpcbind + - git + - which