From 473305da063fcb662fa60f34edde0640918f7728 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Sun, 20 Jun 2021 10:19:27 -0400 Subject: [PATCH] Add tarball install method Depends-On: https://review.opendev.org/c/windmill/windmill/+/795909 Depends-On: https://review.opendev.org/c/windmill/windmill/+/795901 Change-Id: I44d663aea48912a8addbd9288687491fa490703e Signed-off-by: Paul Belanger --- .zuul.yaml | 14 ++++- defaults/main.yaml | 29 +++++++++ tasks/config.yaml | 12 ++++ tasks/install/tarball.yaml | 60 +++++++++++++++++++ tasks/pre.yaml | 36 +++++++++++ tasks/service.yaml | 45 ++++++++++++++ .../etc/systemd/system/zookeeper.service | 18 ++++++ .../system/zookeeper.service.d/override.conf | 3 + 8 files changed, 215 insertions(+), 2 deletions(-) create mode 100644 tasks/install/tarball.yaml create mode 100644 tasks/pre.yaml create mode 100644 templates/etc/systemd/system/zookeeper.service create mode 100644 templates/etc/systemd/system/zookeeper.service.d/override.conf diff --git a/.zuul.yaml b/.zuul.yaml index e80c8ad..ec07681 100644 --- a/.zuul.yaml +++ b/.zuul.yaml @@ -1,13 +1,21 @@ --- - job: - name: ansible-role-zookeeper + name: ansible-role-zookeeper-base run: tests/playbooks/run.yaml roles: - zuul: windmill/ansible-role-zookeeper +- job: + name: ansible-role-zookeeper-tarball + parent: ansible-role-zookeeper-base + nodeset: ubuntu-bionic + vars: + zookeeper_install_method: tarball + zookeeper_tarball_version: 3.5.9 + - job: name: ansible-role-zookeeper-ubuntu-bionic - parent: ansible-role-zookeeper + parent: ansible-role-zookeeper-base nodeset: ubuntu-bionic - project: @@ -15,9 +23,11 @@ - windmill-jobs-bionic check: jobs: + - ansible-role-zookeeper-tarball - ansible-role-zookeeper-ubuntu-bionic - tox-linters gate: jobs: + - ansible-role-zookeeper-tarball - ansible-role-zookeeper-ubuntu-bionic - tox-linters diff --git a/defaults/main.yaml b/defaults/main.yaml index 7a50b83..2fcd4b6 100644 --- a/defaults/main.yaml +++ b/defaults/main.yaml @@ -14,11 +14,18 @@ --- # tasks/main.yaml zookeeper_task_manager: + - pre - install - config - service # tasks/config.yaml +zookeeper_user_name: zookeeper +zookeeper_user_group: zookeeper +zookeeper_user_home: /var/lib/zookeeper +zookeeper_user_home_mode: 0750 +# zookeeper_user_shell: + zookeeper_file_myid_group: zookeeper zookeeper_file_myid_mode: 0644 zookeeper_file_myid_owner: zookeeper @@ -32,7 +39,29 @@ zookeeper_package_state: present zookeeper_install_method: package +zookeeper_tarball_creates: "{{ zookeeper_tarball_dest }}/apache-zookeeper-{{ zookeeper_tarball_version }}-bin" +zookeeper_tarball_dest: "/opt/tarballs" +zookeeper_tarball_remote_src: true +zookeeper_tarball_src: "https://archive.apache.org/dist/zookeeper/zookeeper-{{ zookeeper_tarball_version }}/apache-zookeeper-{{ zookeeper_tarball_version }}-bin.tar.gz" +zookeeper_tarball_symlink: /opt/zookeeper +zookeeper_tarball_version: + # tasks/service.yaml +zookeeper_file_zookeeper_service_dest: /etc/systemd/system/zookeeper.service +zookeeper_file_zookeeper_service_group: root +zookeeper_file_zookeeper_service_manage: true +zookeeper_file_zookeeper_service_mode: 0644 +zookeeper_file_zookeeper_service_owner: root +zookeeper_file_zookeeper_service_src: etc/systemd/system/zookeeper.service + +zookeeper_file_zookeeper_service_config_dest: /etc/systemd/system/zookeeper.service.d/override.conf +zookeeper_file_zookeeper_service_config_group: root +zookeeper_file_zookeeper_service_config_manage: true +zookeeper_file_zookeeper_service_config_mode: 0644 +zookeeper_file_zookeeper_service_config_owner: root +zookeeper_file_zookeeper_service_config_src: etc/systemd/system/zookeeper.service.d/override.conf + +zookeeper_service_zookeeper_daemon_reload: true zookeeper_service_zookeeper_enabled: yes zookeeper_service_zookeeper_manage: true zookeeper_service_zookeeper_name: zookeeper diff --git a/tasks/config.yaml b/tasks/config.yaml index 3a2ebd8..fbc2098 100644 --- a/tasks/config.yaml +++ b/tasks/config.yaml @@ -32,6 +32,18 @@ zookeeper_file_zoo_conf_src: "{{ __zookeeper_file_zoo_conf_src }}" when: zookeeper_file_zoo_conf_src is not defined +- name: Create required directories + become: true + file: + group: "{{ zookeeper_user_group }}" + owner: "{{ zookeeper_user_name }}" + path: "{{ item }}" + state: directory + with_items: + - /etc/zookeeper + - /etc/zookeeper/conf + - /var/log/zookeeper + - name: Install zookeeper myid become: yes template: diff --git a/tasks/install/tarball.yaml b/tasks/install/tarball.yaml new file mode 100644 index 0000000..6b65ce8 --- /dev/null +++ b/tasks/install/tarball.yaml @@ -0,0 +1,60 @@ +# Copyright 2021 Red Hat, Inc. +# +# 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: Ensure java is present + become: true + package: + name: default-jre-headless + state: present + +- name: Create required directory + become: true + file: + path: "{{ zookeeper_tarball_dest }}" + state: directory + +- name: Ensure zookeeper is present + become: true + unarchive: + creates: "{{ zookeeper_tarball_creates }}" + dest: "{{ zookeeper_tarball_dest }}" + remote_src: "{{ zookeeper_tarball_remote_src }}" + src: "{{ zookeeper_tarball_src }}" + +- name: Stat zookeeper_tarball_symlink + stat: + path: "{{ zookeeper_tarball_symlink | dirname }}" + register: r + no_log: true + when: zookeeper_tarball_symlink is defined + +- name: Create zookeeper_tarball_symlink directory + become: true + file: + state: directory + path: "{{ zookeeper_tarball_symlink | dirname }}" + when: + - zookeeper_tarball_symlink is defined + - not r.stat.exists + +- name: Symlink zookeeper tarball + become: true + file: + dest: "{{ zookeeper_tarball_symlink }}" + src: "{{ zookeeper_tarball_creates }}" + state: link + when: + - zookeeper_tarball_creates is defined + - zookeeper_tarball_symlink is defined + - zookeeper_tarball_creates != zookeeper_tarball_symlink diff --git a/tasks/pre.yaml b/tasks/pre.yaml new file mode 100644 index 0000000..72ca84f --- /dev/null +++ b/tasks/pre.yaml @@ -0,0 +1,36 @@ +# Copyright 2021 Red Hat, Inc. +# +# 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 zookeeper user / group + block: + - name: Create group account + become: true + group: + name: "{{ zookeeper_user_group }}" + + - name: Create user account + become: true + user: + createhome: true + group: "{{ zookeeper_user_group }}" + home: "{{ zookeeper_user_home }}" + name: "{{ zookeeper_user_name }}" + shell: "{{ zookeeper_user_shell|default(omit) }}" + + - name: Set permissions on home directory + become: true + file: + path: "{{ zookeeper_user_home }}" + mode: "{{ zookeeper_user_home_mode }}" + when: zookeeper_install_method != 'package' diff --git a/tasks/service.yaml b/tasks/service.yaml index e1ae709..972bf0a 100644 --- a/tasks/service.yaml +++ b/tasks/service.yaml @@ -12,6 +12,40 @@ # License for the specific language governing permissions and limitations # under the License. --- +- name: Install systemd files + block: + - name: Install zookeeper service script into place + become: true + template: + dest: "{{ zookeeper_file_zookeeper_service_dest }}" + group: "{{ zookeeper_file_zookeeper_service_group }}" + mode: "{{ zookeeper_file_zookeeper_service_mode }}" + owner: "{{ zookeeper_file_zookeeper_service_owner }}" + src: "{{ zookeeper_file_zookeeper_service_src }}" + register: zookeeper_file_zookeeper_service + when: zookeeper_file_zookeeper_service_manage + + - name: Create zookeeper service config directory + become: true + file: + group: "{{ zookeeper_file_zookeeper_service_config_group }}" + owner: "{{ zookeeper_file_zookeeper_service_config_owner }}" + path: "{{ zookeeper_file_zookeeper_service_dest }}.d" + state: directory + when: zookeeper_file_zookeeper_service_config_manage + + - name: Install zookeeper service config into place + become: true + template: + dest: "{{ zookeeper_file_zookeeper_service_config_dest }}" + group: "{{ zookeeper_file_zookeeper_service_config_group }}" + mode: "{{ zookeeper_file_zookeeper_service_config_mode }}" + owner: "{{ zookeeper_file_zookeeper_service_config_owner }}" + src: "{{ zookeeper_file_zookeeper_service_config_src }}" + register: zookeeper_file_zookeeper_service_config + when: zookeeper_file_zookeeper_service_config_manage + when: zookeeper_install_method != 'package' + - name: Enable zookeeper service become: yes service: @@ -20,3 +54,14 @@ state: "{{ zookeeper_service_zookeeper_state }}" register: zookeeper_service_zookeeper when: zookeeper_service_zookeeper_manage + +- name: Set zookeeper service state + become: true + systemd: + daemon_reload: "{{ zookeeper_service_zookeeper_daemon_reload }}" + name: "{{ zookeeper_service_zookeeper_name }}" + state: "{{ zookeeper_service_zookeeper_state }}" + register: zookeeper_service_zookeeper_state_info + when: + - zookeeper_service_zookeeper_manage + - zookeeper_service_zookeeper_state in ['reloaded', 'restarted', 'started', 'stopped'] diff --git a/templates/etc/systemd/system/zookeeper.service b/templates/etc/systemd/system/zookeeper.service new file mode 100644 index 0000000..df23b71 --- /dev/null +++ b/templates/etc/systemd/system/zookeeper.service @@ -0,0 +1,18 @@ +[Unit] +Description=ZooKeeper Service +Documentation=http://zookeeper.apache.org +Requires=network.target +After=network.target + +[Service] +Type=forking +User=zookeeper +Group=zookeeper +Environment=ZOO_LOG_DIR=/var/log/zookeeper +ExecStart=/opt/zookeeper/bin/zkServer.sh --config /etc/zookeeper/conf start +ExecStop=/opt/zookeeper/bin/zkServer.sh --config /etc/zookeeper/conf stop +ExecReload=/opt/zookeeper/bin/zkServer.sh --config /etc/zookeeper/conf restart +WorkingDirectory=/opt/zookeeper + +[Install] +WantedBy=default.target diff --git a/templates/etc/systemd/system/zookeeper.service.d/override.conf b/templates/etc/systemd/system/zookeeper.service.d/override.conf new file mode 100644 index 0000000..602ac8e --- /dev/null +++ b/templates/etc/systemd/system/zookeeper.service.d/override.conf @@ -0,0 +1,3 @@ +# This file is generated by Ansible +# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN +#