summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Carter <kevin.carter@rackspace.com>2018-07-30 09:00:10 -0500
committerKevin Carter (cloudnull) <kevin@cloudnull.com>2018-07-30 23:12:38 +0000
commiteac3740711ba9672d46cb91e2e99c583d2371eb4 (patch)
tree4eaa3e6c11cc630c1dd3e1bebe74fef107cf8b47
parentbe6bbec45915ddaf286d5965c65b1d67eeb30260 (diff)
Convert role to use a common systemd service role
This removes the systemd service templates and tasks from this role and leverages a common systemd service role instead. This change removes a lot of code duplication across all roles all without sacrificing features or functionality. The intention of this change is to ensure uniformity and reduce the maintenance burden on the community when sweeping changes are needed. Change-Id: Id817631699d711993bbdad08660d8067550430e6 Signed-off-by: Kevin Carter <kevin.carter@rackspace.com>
Notes
Notes (review): Code-Review+2: Jesse Pretorius (odyssey4me) <jesse.pretorius@rackspace.co.uk> Workflow+1: Jesse Pretorius (odyssey4me) <jesse.pretorius@rackspace.co.uk> Verified+2: Zuul Submitted-by: Zuul Submitted-at: Tue, 31 Jul 2018 08:20:54 +0000 Reviewed-on: https://review.openstack.org/587070 Project: openstack/openstack-ansible-os_almanach Branch: refs/heads/master
-rw-r--r--defaults/main.yml28
-rw-r--r--handlers/main.yml4
-rw-r--r--tasks/almanach_init.yml30
-rw-r--r--tasks/almanach_init_systemd.yml24
-rw-r--r--tasks/almanach_install.yml39
-rw-r--r--tasks/main.yml41
-rw-r--r--templates/almanach-systemd-init.j231
-rw-r--r--templates/almanach.conf.j21
-rw-r--r--vars/main.yml31
-rw-r--r--vars/ubuntu-14.04.yml17
-rw-r--r--vars/ubuntu-16.04.yml8
11 files changed, 120 insertions, 134 deletions
diff --git a/defaults/main.yml b/defaults/main.yml
index bc33865..79206e0 100644
--- a/defaults/main.yml
+++ b/defaults/main.yml
@@ -18,16 +18,30 @@ almanach_version: 4.0.9
18almanach_collector_program_name: almanach-collector 18almanach_collector_program_name: almanach-collector
19almanach_api_program_name: almanach-api 19almanach_api_program_name: almanach-api
20 20
21almanach_service_names: 21almanach_venv_tag: untagged
22 - "almanach-api" 22almanach_bin: "/openstack/venvs/almanach-{{ almanach_venv_tag }}/bin"
23 - "almanach-collector" 23
24 24almanach_services:
25almanach_requires_apt_packages: 25 almanach-api:
26 - python3-pip 26 group: almanach_all
27 service_name: almanach-api
28 init_config_overrides: "{{ almanach_api_init_config_overrides }}"
29 start_order: 1
30 execstarts: "{{ almanach_bin }}/almanach-api"
31 almanach-collector:
32 group: almanach_all
33 service_name: almanach-collector
34 init_config_overrides: "{{ almanach_collector_init_config_overrides }}"
35 start_order: 2
36 execstarts: "{{ almanach_bin }}/almanach-collector"
27 37
28almanach_requires_pip_packages: 38almanach_requires_pip_packages:
29 - virtualenv 39 - virtualenv
30 40
41almanach_pip_packages:
42 - "almanach=={{ almanach_version }}"
43 - systemd-python
44
31almanach_system_user_name: almanach 45almanach_system_user_name: almanach
32almanach_system_group_name: almanach 46almanach_system_group_name: almanach
33almanach_system_shell: /bin/false 47almanach_system_shell: /bin/false
@@ -36,8 +50,6 @@ almanach_system_comment: almanach system user
36almanach_log_dir: /var/log/almanach 50almanach_log_dir: /var/log/almanach
37almanach_log_file: /var/log/almanach/almanach.log 51almanach_log_file: /var/log/almanach/almanach.log
38 52
39almanach_app_dir: /opt/almanach
40
41almanach_config_dir: /etc/almanach 53almanach_config_dir: /etc/almanach
42almanach_config_file: /etc/almanach/almanach.conf 54almanach_config_file: /etc/almanach/almanach.conf
43almanach_logrotate_config_file: /etc/logrotate.d/almanach 55almanach_logrotate_config_file: /etc/logrotate.d/almanach
diff --git a/handlers/main.yml b/handlers/main.yml
index 042d3b7..f941101 100644
--- a/handlers/main.yml
+++ b/handlers/main.yml
@@ -26,7 +26,7 @@
26 26
27- name: Restart almanach services 27- name: Restart almanach services
28 systemd: 28 systemd:
29 name: "{{ item }}" 29 name: "{{ item.service_name }}"
30 state: "restarted" 30 state: "restarted"
31 with_items: "{{ almanach_service_names }}" 31 with_items: "{{ filtered_almanach_services }}"
32 failed_when: false 32 failed_when: false
diff --git a/tasks/almanach_init.yml b/tasks/almanach_init.yml
deleted file mode 100644
index 05b9be3..0000000
--- a/tasks/almanach_init.yml
+++ /dev/null
@@ -1,30 +0,0 @@
1---
2# Copyright 2016, Internap Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16- include: almanach_init_systemd.yml
17 vars:
18 program_name: "{{ almanach_api_program_name }}"
19 service_name: "almanach-api"
20 system_user: "{{ almanach_system_user_name }}"
21 system_group: "{{ almanach_system_group_name }}"
22 init_config_overrides: "{{ almanach_api_init_config_overrides }}"
23
24- include: almanach_init_systemd.yml
25 vars:
26 program_name: "{{ almanach_collector_program_name }}"
27 service_name: "almanach-collector"
28 system_user: "{{ almanach_system_user_name }}"
29 system_group: "{{ almanach_system_group_name }}"
30 init_config_overrides: "{{ almanach_collector_init_config_overrides }}"
diff --git a/tasks/almanach_init_systemd.yml b/tasks/almanach_init_systemd.yml
deleted file mode 100644
index e74e8fd..0000000
--- a/tasks/almanach_init_systemd.yml
+++ /dev/null
@@ -1,24 +0,0 @@
1---
2# Copyright 2016, Internap Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16- name: Place the systemd init script
17 template:
18 src: "almanach-systemd-init.j2"
19 dest: "/etc/systemd/system/{{ program_name }}.service"
20 mode: "0644"
21 owner: "root"
22 group: "root"
23 notify:
24 - Restart almanach services
diff --git a/tasks/almanach_install.yml b/tasks/almanach_install.yml
index b990871..bd8dc2c 100644
--- a/tasks/almanach_install.yml
+++ b/tasks/almanach_install.yml
@@ -13,20 +13,45 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16- name: Update APT index
17 apt: update_cache=yes
18 become: True
19
20- name: Install apt packages 16- name: Install apt packages
21 apt: 17 package:
22 name: "{{ almanach_requires_apt_packages | join(' ') }}" 18 name: "{{ almanach_requires_apt_packages | join(' ') }}"
23 state: present 19 state: present
20 update_cache: yes
21 register: install_packages
22 until: install_packages is success
23 retries: 5
24 delay: 2
25
26# NOTE(cloudnull): This role has no "developer_mode" as such the developer
27# packages are simply installed.
28- name: Install developer apt packages
29 package:
30 name: "{{ almanach_developer_mode_distro_packages }}"
31 state: present
32 update_cache: yes
33 register: install_packages
34 until: install_packages is success
35 retries: 5
36 delay: 2
24 37
25- name: Install pip packages 38- name: Install pip packages
26 pip: 39 pip:
27 name: "{{ almanach_requires_pip_packages }}" 40 name: "{{ almanach_requires_pip_packages }}"
28 state: present 41 state: present
29 executable: pip3 42 executable: pip3
43 register: install_packages
44 until: install_packages is success
45 retries: 5
46 delay: 2
30 47
31- name: Install Almanach 48- name: Install pip packages
32 pip: name=almanach version={{ almanach_version }} virtualenv={{ almanach_app_dir }} virtualenv_python=python3 49 pip:
50 name: "{{ almanach_pip_packages }}"
51 state: present
52 virtualenv: "/openstack/venvs/almanach-{{ almanach_venv_tag }}"
53 virtualenv_python: "python3"
54 register: install_packages
55 until: install_packages is success
56 retries: 5
57 delay: 2
diff --git a/tasks/main.yml b/tasks/main.yml
index 8064b72..8d8045f 100644
--- a/tasks/main.yml
+++ b/tasks/main.yml
@@ -24,19 +24,6 @@
24 tags: 24 tags:
25 - always 25 - always
26 26
27- name: Check init system
28 command: cat /proc/1/comm
29 changed_when: false
30 register: _pid1_name
31 tags:
32 - always
33
34- name: Set the name of pid1
35 set_fact:
36 pid1_name: "{{ _pid1_name.stdout }}"
37 tags:
38 - always
39
40- include: almanach_pre_install.yml 27- include: almanach_pre_install.yml
41 tags: 28 tags:
42 - almanach-install 29 - almanach-install
@@ -50,6 +37,30 @@
50 - almanach-install 37 - almanach-install
51 - almanach-config 38 - almanach-config
52 39
53- include: almanach_init.yml 40- name: Run the systemd service role
41 include_role:
42 name: systemd_service
43 private: true
44 vars:
45 systemd_user_name: "{{ almanach_system_user_name }}"
46 systemd_group_name: "{{ almanach_system_group_name }}"
47 systemd_tempd_prefix: openstack
48 systemd_slice_name: almanach
49 systemd_lock_path: /var/lock/almanach
50 systemd_CPUAccounting: true
51 systemd_BlockIOAccounting: true
52 systemd_MemoryAccounting: true
53 systemd_TasksAccounting: true
54 systemd_services:
55 - service_name: "{{ service_var.service_name }}"
56 enabled: yes
57 state: started
58 execstarts: "{{ service_var.execstarts }}"
59 execreloads: "{{ service_var.execreloads | default([]) }}"
60 config_overrides: "{{ service_var.init_config_overrides }}"
61 with_items: "{{ filtered_almanach_services }}"
62 loop_control:
63 loop_var: service_var
54 tags: 64 tags:
55 - almanach-install 65 - almanach-config
66 - systemd-service
diff --git a/templates/almanach-systemd-init.j2 b/templates/almanach-systemd-init.j2
deleted file mode 100644
index 24ed015..0000000
--- a/templates/almanach-systemd-init.j2
+++ /dev/null
@@ -1,31 +0,0 @@
1# {{ ansible_managed }}
2
3[Unit]
4Description=Almanach api openstack service
5After=syslog.target
6After=network.target
7
8[Service]
9Type=simple
10EnvironmentFile=/etc/environment
11User={{ system_user }}
12Group={{ system_group }}
13
14ExecStart={{ almanach_app_dir }}/bin/{{ program_name }} --config-file={{ almanach_config_file }} --log-file={{ almanach_log_file }}
15
16# Give a reasonable amount of time for the server to start up/shut down
17TimeoutSec=120
18Restart=on-failure
19RestartSec=2
20
21# This creates a specific slice which all services will operate from
22# The accounting options give us the ability to see resource usage through
23# the `systemd-cgtop` command.
24Slice=almanach.slice
25CPUAccounting=true
26BlockIOAccounting=true
27MemoryAccounting=false
28TasksAccounting=true
29
30[Install]
31WantedBy=multi-user.target
diff --git a/templates/almanach.conf.j2 b/templates/almanach.conf.j2
index 6aeddca..f4fe0bd 100644
--- a/templates/almanach.conf.j2
+++ b/templates/almanach.conf.j2
@@ -1,4 +1,5 @@
1[DEFAULT] 1[DEFAULT]
2use_journal = True
2 3
3[api] 4[api]
4bind_ip = {{ almanach_bind_ip }} 5bind_ip = {{ almanach_bind_ip }}
diff --git a/vars/main.yml b/vars/main.yml
new file mode 100644
index 0000000..29ef4b0
--- /dev/null
+++ b/vars/main.yml
@@ -0,0 +1,31 @@
1---
2# Copyright 2018, Rackspace US, Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16#
17# Compile a list of the services on a host based on whether
18# the host is in the host group and the service is enabled.
19# The service list is provided in the defined start order.
20#
21filtered_almanach_services: |-
22 {% set services = [] %}
23 {% for key, value in almanach_services.items() %}
24 {% if (value['group'] in group_names) and
25 (('condition' not in value) or
26 ('condition' in value and value['condition'])) %}
27 {% set _ = value.update({'service_key': key}) %}
28 {% set _ = services.append(value) %}
29 {% endif %}
30 {% endfor %}
31 {{ services | sort(attribute='start_order') }}
diff --git a/vars/ubuntu-14.04.yml b/vars/ubuntu-14.04.yml
deleted file mode 100644
index 6bee34f..0000000
--- a/vars/ubuntu-14.04.yml
+++ /dev/null
@@ -1,17 +0,0 @@
1---
2# Copyright 2016, Internap Inc.
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16## APT Cache options
17cache_timeout: 600
diff --git a/vars/ubuntu-16.04.yml b/vars/ubuntu-16.04.yml
index 6bee34f..035b146 100644
--- a/vars/ubuntu-16.04.yml
+++ b/vars/ubuntu-16.04.yml
@@ -15,3 +15,11 @@
15 15
16## APT Cache options 16## APT Cache options
17cache_timeout: 600 17cache_timeout: 600
18
19almanach_requires_apt_packages:
20 - python3-pip
21
22almanach_developer_mode_distro_packages:
23 - build-essential
24 - libsystemd-dev
25 - pkg-config