From 15c80abdbc043f16dbb24a12217def2b59ae40ce Mon Sep 17 00:00:00 2001 From: Jimmy McCrory Date: Mon, 25 Jul 2016 10:10:11 -0700 Subject: [PATCH] Implement Multi-OS support in os_cloudkitty This change implements support for Xenial and CentOS 7 within the os_cloudkitty role. Change-Id: Id2abe9099171080bd3d3ceb3a54222a5dfdefe2f Implements: blueprint multi-platform-host --- meta/main.yml | 4 ++ ...y_upstart_init.yml => cloudkitty_init.yml} | 6 +-- tasks/cloudkitty_init_common.yml | 27 ++++++++++ tasks/cloudkitty_init_systemd.yml | 53 +++++++++++++++++++ ...n_init.yml => cloudkitty_init_upstart.yml} | 2 +- tasks/cloudkitty_install.yml | 12 +++++ ...all_apt.yml => cloudkitty_install_apt.yml} | 4 +- tasks/cloudkitty_install_yum.yml | 24 +++++++++ tasks/main.yml | 32 +++++++---- templates/cloudkitty-systemd-init.j2 | 25 +++++++++ templates/cloudkitty-systemd-tempfiles.j2 | 4 ++ vars/debian.yml | 20 +++++++ vars/redhat.yml | 17 ++++++ 13 files changed, 215 insertions(+), 15 deletions(-) rename tasks/{cloudkitty_upstart_init.yml => cloudkitty_init.yml} (93%) create mode 100644 tasks/cloudkitty_init_common.yml create mode 100644 tasks/cloudkitty_init_systemd.yml rename tasks/{cloudkitty_upstart_common_init.yml => cloudkitty_init_upstart.yml} (96%) rename tasks/{install_apt.yml => cloudkitty_install_apt.yml} (93%) create mode 100644 tasks/cloudkitty_install_yum.yml create mode 100644 templates/cloudkitty-systemd-init.j2 create mode 100644 templates/cloudkitty-systemd-tempfiles.j2 create mode 100644 vars/debian.yml create mode 100644 vars/redhat.yml diff --git a/meta/main.yml b/meta/main.yml index c32e6d0..5ebeee5 100644 --- a/meta/main.yml +++ b/meta/main.yml @@ -23,6 +23,10 @@ galaxy_info: - name: Ubuntu versions: - trusty + - xenial + - name: EL + versions: + - 7 categories: - cloud - python diff --git a/tasks/cloudkitty_upstart_init.yml b/tasks/cloudkitty_init.yml similarity index 93% rename from tasks/cloudkitty_upstart_init.yml rename to tasks/cloudkitty_init.yml index fbde18e..9cfa0fa 100644 --- a/tasks/cloudkitty_upstart_init.yml +++ b/tasks/cloudkitty_init.yml @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -- include: cloudkitty_upstart_common_init.yml +- include: cloudkitty_init_common.yml vars: program_name: "{{ cloudkitty_service_program_name }}" service_name: "{{ cloudkitty_service_name }}" @@ -22,7 +22,8 @@ service_home: "{{ cloudkitty_system_home_folder }}" when: > inventory_hostname in groups['cloudkitty_api'] -- include: cloudkitty_upstart_common_init.yml + +- include: cloudkitty_init_common.yml vars: program_name: "{{ cloudkitty_service_processor_program_name }}" service_name: "{{ cloudkitty_service_name }}" @@ -31,4 +32,3 @@ service_home: "{{ cloudkitty_system_home_folder }}" when: > inventory_hostname in groups['cloudkitty_api'] - diff --git a/tasks/cloudkitty_init_common.yml b/tasks/cloudkitty_init_common.yml new file mode 100644 index 0000000..e30f3be --- /dev/null +++ b/tasks/cloudkitty_init_common.yml @@ -0,0 +1,27 @@ +--- +# Copyright 2016, Rackspace US, 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. + +- include: cloudkitty_init_upstart.yml + when: pid1_name == "init" + +- include: cloudkitty_init_systemd.yml + when: pid1_name == "systemd" + +- name: Load service + service: + name: "{{ program_name }}" + enabled: "yes" + notify: + - Restart cloudkitty services diff --git a/tasks/cloudkitty_init_systemd.yml b/tasks/cloudkitty_init_systemd.yml new file mode 100644 index 0000000..f95208a --- /dev/null +++ b/tasks/cloudkitty_init_systemd.yml @@ -0,0 +1,53 @@ +--- +# Copyright 2016, Rackspace US, 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 TEMP run dir + file: + path: "/var/run/{{ program_name }}" + state: directory + owner: "{{ system_user }}" + group: "{{ system_group }}" + mode: "02755" + +- name: Create TEMP lock dir + file: + path: "/var/lock/{{ program_name }}" + state: directory + owner: "{{ system_user }}" + group: "{{ system_group }}" + mode: "02755" + +- name: Create tempfile.d entry + template: + src: "cloudkitty-systemd-tempfiles.j2" + dest: "/etc/tmpfiles.d/cloudkitty.conf" + mode: "0644" + owner: "root" + group: "root" + +- name: Place the systemd init script + template: + src: "cloudkitty-systemd-init.j2" + dest: "/etc/systemd/system/{{ program_name }}.service" + mode: "0644" + owner: "root" + group: "root" + register: systemd_init + +- name: Reload the systemd daemon + command: "systemctl daemon-reload" + when: systemd_init | changed + notify: + - Restart cloudkitty services diff --git a/tasks/cloudkitty_upstart_common_init.yml b/tasks/cloudkitty_init_upstart.yml similarity index 96% rename from tasks/cloudkitty_upstart_common_init.yml rename to tasks/cloudkitty_init_upstart.yml index 1e72037..aba2599 100644 --- a/tasks/cloudkitty_upstart_common_init.yml +++ b/tasks/cloudkitty_init_upstart.yml @@ -1,5 +1,5 @@ --- -# Copyright 2014, Rackspace US, Inc. +# Copyright 2016, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. diff --git a/tasks/cloudkitty_install.yml b/tasks/cloudkitty_install.yml index 9d277ef..8466fce 100644 --- a/tasks/cloudkitty_install.yml +++ b/tasks/cloudkitty_install.yml @@ -15,6 +15,18 @@ # See the License for the specific language governing permissions and # limitations under the License. +- include: cloudkitty_install_apt.yml + when: + - ansible_pkg_mgr == 'apt' + tags: + - cloudkitty-install + +- include: cloudkitty_install_yum.yml + when: + - ansible_pkg_mgr == 'yum' + tags: + - cloudkitty-install + - name: Create developer mode constraint file copy: dest: "/opt/developer-pip-constraints.txt" diff --git a/tasks/install_apt.yml b/tasks/cloudkitty_install_apt.yml similarity index 93% rename from tasks/install_apt.yml rename to tasks/cloudkitty_install_apt.yml index 26743cf..e07425b 100644 --- a/tasks/install_apt.yml +++ b/tasks/cloudkitty_install_apt.yml @@ -1,5 +1,5 @@ --- -# Copyright 2014, Rackspace US, Inc. +# Copyright 2016, Rackspace US, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ until: install_packages|success retries: 5 delay: 2 - with_items: "{{ cloudkitty_apt_packages }}" + with_items: "{{ cloudkitty_packages }}" tags: - cloudkitty-install - cloudkitty-apt-packages diff --git a/tasks/cloudkitty_install_yum.yml b/tasks/cloudkitty_install_yum.yml new file mode 100644 index 0000000..cce25dc --- /dev/null +++ b/tasks/cloudkitty_install_yum.yml @@ -0,0 +1,24 @@ +--- +# Copyright 2016, Rackspace US, 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: Install yum packages + yum: + pkg: "{{ item }}" + state: latest + register: install_packages + until: install_packages|success + retries: 5 + delay: 2 + with_items: "{{ cloudkitty_packages }}" diff --git a/tasks/main.yml b/tasks/main.yml index 4ba6925..fb7a17c 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -15,14 +15,28 @@ # See the License for the specific language governing permissions and # limitations under the License. -#- name: Gather variables for each operating system -# include_vars: "{{ item }}" -# with_first_found: -# - "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml" -# - "{{ ansible_distribution | lower }}.yml" -# - "{{ ansible_os_family | lower }}.yml" -# tags: -# - always +- name: Gather variables for each operating system + 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 }}.yml" + tags: + - always + +- name: Check init system + command: cat /proc/1/comm + register: _pid1_name + tags: + - always + +- name: Set the name of pid1 + set_fact: + pid1_name: "{{ _pid1_name.stdout }}" + tags: + - always - include: cloudkitty_pre_install.yml - include: cloudkitty_install.yml @@ -36,7 +50,7 @@ when: > inventory_hostname == groups['cloudkitty_all'][0] -- include: cloudkitty_upstart_init.yml +- include: cloudkitty_init.yml - name: Flush handlers meta: flush_handlers diff --git a/templates/cloudkitty-systemd-init.j2 b/templates/cloudkitty-systemd-init.j2 new file mode 100644 index 0000000..c82bd87 --- /dev/null +++ b/templates/cloudkitty-systemd-init.j2 @@ -0,0 +1,25 @@ +# {{ ansible_managed }} + +[Unit] +Description=cloudkitty openstack service +After=syslog.target +After=network.target + +[Service] +Type=simple +User={{ system_user }} +Group={{ system_group }} + +{% if program_override is defined %} +ExecStart={{ program_override }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ program_name }}.log +{% else %} +ExecStart={{ cloudkitty_bin }}/{{ program_name }} {{ program_config_options|default('') }} --log-file=/var/log/cloudkitty/{{ program_name }}.log +{% endif %} + +# Give a reasonable amount of time for the server to start up/shut down +TimeoutSec=300 +Restart=on-failure +RestartSec=150 + +[Install] +WantedBy=multi-user.target diff --git a/templates/cloudkitty-systemd-tempfiles.j2 b/templates/cloudkitty-systemd-tempfiles.j2 new file mode 100644 index 0000000..b723d85 --- /dev/null +++ b/templates/cloudkitty-systemd-tempfiles.j2 @@ -0,0 +1,4 @@ +# {{ 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/vars/debian.yml b/vars/debian.yml new file mode 100644 index 0000000..041ab9c --- /dev/null +++ b/vars/debian.yml @@ -0,0 +1,20 @@ +--- +# Copyright 2016, Walmart Stores, 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. + +## APT Cache options +cache_timeout: 600 + +cloudkitty_packages: + - git diff --git a/vars/redhat.yml b/vars/redhat.yml new file mode 100644 index 0000000..2e363ef --- /dev/null +++ b/vars/redhat.yml @@ -0,0 +1,17 @@ +--- +# Copyright 2016, Walmart Stores, 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. + +cloudkitty_packages: + - git