Multi-distro framework for rabbitmq_server role

Separate files have been created for vars and tasks related to a
specific package manager. The 'vars_files_var' variable has been created
to store a list of files to search for distro specific variables.

The 'rabbitmq_apt_packages' variable has been deprecated and renamed to
the more generalized 'rabbitmq_dependencies' to better describe its
purpose and to simplify reuse of existing install tasks between multiple
distros.

Change-Id: I1940593978b733501daf5fe25edd393f2f6bee0c
This commit is contained in:
Jimmy McCrory 2016-02-29 13:06:21 -08:00
parent 4ee710c9bf
commit d6a1f3d619
21 changed files with 292 additions and 69 deletions

View File

@ -26,13 +26,11 @@ rabbitmq_upgrade: false
# upgrade/version state can be ignored by setting `rabbitmq_ignore_version_state=true`
rabbitmq_ignore_version_state: false
rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server_3.6.1-1_all.deb"
rabbitmq_package_version: "{{ rabbitmq_package_url.split('/')[-1].split('_')[1] }}"
rabbitmq_package_sha256: "0728fbdb14ec62712c6f931a7d91648cafbc6c30d8d4da790832e784b4d2e956"
rabbitmq_package_path: "/opt/rabbitmq-server.deb"
rabbitmq_apt_packages:
- erlang-nox
rabbitmq_package_url: "{{ _rabbitmq_package_url }}"
rabbitmq_package_version: "{{ _rabbitmq_package_version }}"
rabbitmq_release_version: "{{ _rabbitmq_release_version }}"
rabbitmq_package_sha256: "{{ _rabbitmq_package_sha256 }}"
rabbitmq_package_path: "{{ _rabbitmq_package_path }}"
rabbitmq_pip_packages:
- pycrypto

View File

@ -23,11 +23,17 @@ galaxy_info:
- name: Ubuntu
versions:
- trusty
- xenial
- name: EL
versions:
- 7
categories:
- cloud
- rabbitmq
- development
- openstack
dependencies:
- apt_package_pinning
- pip_install
- role: apt_package_pinning
when:
- ansible_pkg_mgr == 'apt'
- pip_install

View File

@ -14,7 +14,13 @@
# TODO(odyssey4me) remove this once https://review.openstack.org/288634 has merged
# and the disk images are rebuilt and redeployed.
curl
wget
# Requirements for Paramiko 2.0
libssl-dev
libffi-dev
libssl-dev [platform:dpkg]
libffi-dev [platform:dpkg]
libffi-devel [platform:rpm]
openssl-devel [platform:rpm]
# For selinux
libselinux-python [platform:rpm]

View File

@ -0,0 +1,5 @@
---
deprecations:
- The ``rabbitmq_apt_packages`` variable has been deprecated.
``rabbitmq_dependencies`` should be used instead to override
additional packages to install alongside rabbitmq-server.

50
tasks/install_apt.yml Normal file
View File

@ -0,0 +1,50 @@
---
# Copyright 2014, 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.
#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged
#in 1.9.x or we move to 2.0 (if tested working)
- name: Check apt last update file
stat:
path: /var/cache/apt
register: apt_cache_stat
tags:
- rabbitmq-apt-packages
- name: Update apt if needed
apt:
update_cache: yes
when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
tags:
- rabbitmq-apt-packages
- name: Install RabbitMQ package dependencies
apt:
pkg: "{{ item }}"
state: latest
register: install_packages
until: install_packages|success
retries: 5
delay: 2
with_items: "{{ rabbitmq_dependencies | deprecated(rabbitmq_apt_packages, 'rabbitmq_apt_packages', 'rabbitmq_dependencies', 'Ocata') }}"
tags:
- rabbitmq-apt-packages
- name: Install the RabbitMQ package
apt:
deb: "{{ rabbitmq_package_path }}"
tags:
- rabbitmq-package-deb
- rabbitmq-apt-packages

42
tasks/install_yum.yml Normal file
View File

@ -0,0 +1,42 @@
---
# 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.
- name: Install epel-release package
yum:
name: epel-release
state: present
update_cache: yes
tags:
- rabbitmq-yum-packages
- name: Install RabbitMQ package dependencies
yum:
pkg: "{{ item }}"
state: latest
update_cache: yes
register: install_packages
until: install_packages|success
retries: 5
delay: 2
with_items: rabbitmq_dependencies
tags:
- rabbitmq-yum-packages
- name: Install the RabbitMQ package
yum:
name: "{{ rabbitmq_package_path }}"
tags:
- rabbitmq-package-rpm
- rabbitmq-yum-packages

View File

@ -13,6 +13,16 @@
# 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_release | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_version | lower }}.yml"
- "{{ ansible_distribution | lower }}-{{ ansible_distribution_major_version | lower }}.yml"
- "{{ ansible_distribution | lower }}.yml"
- "{{ ansible_os_family | lower }}.yml"
tags:
- always
- include: rabbitmq_pre_install.yml

View File

@ -15,41 +15,17 @@
- include: rabbitmq_upgrade_check.yml
#TODO(evrardjp): Replace the next 2 tasks by a standard apt with cache
#when https://github.com/ansible/ansible-modules-core/pull/1517 is merged
#in 1.9.x or we move to 2.0 (if tested working)
- name: Check apt last update file
stat:
path: /var/cache/apt
register: apt_cache_stat
- include: install_apt.yml
when:
- ansible_pkg_mgr == 'apt'
tags:
- rabbitmq-apt-packages
- name: Update apt if needed
apt:
update_cache: yes
when: "ansible_date_time.epoch|float - apt_cache_stat.stat.mtime > {{cache_timeout}}"
- include: install_yum.yml
when:
- ansible_pkg_mgr == 'yum'
tags:
- rabbitmq-apt-packages
- name: Install apt packages
apt:
pkg: "{{ item }}"
state: latest
register: install_packages
until: install_packages|success
retries: 5
delay: 2
with_items: rabbitmq_apt_packages
tags:
- rabbitmq-apt-packages
- name: Install the RabbitMQ package
apt:
deb: "{{ rabbitmq_package_path }}"
tags:
- rabbitmq-package-deb
- rabbitmq-apt-packages
- rabbitmq-yum-packages
- name: Install pip packages
pip:

View File

@ -21,6 +21,8 @@
- rabbitmq-upgrade
- rabbitmq-package-deb
- rabbitmq-package-deb-get
- rabbitmq-package-rpm
- rabbitmq-package-rpm-get
- name: Download the RabbitMQ package
get_url:
@ -35,6 +37,8 @@
tags:
- rabbitmq-package-deb
- rabbitmq-package-deb-get
- rabbitmq-package-rpm
- rabbitmq-package-rpm-get
- name: Fix /etc/hosts
lineinfile:

View File

@ -17,6 +17,7 @@
service:
name: rabbitmq-server
state: started
enabled: yes
failed_when: false
when: >
ansible_hostname == rabbitmq_primary_cluster_node
@ -29,6 +30,7 @@
service:
name: rabbitmq-server
state: started
enabled: yes
failed_when: false
when: >
ansible_hostname != rabbitmq_primary_cluster_node

View File

@ -13,26 +13,48 @@
# See the License for the specific language governing permissions and
# limitations under the License.
- name: Get version of installed RabbitMQ package
- name: Get version of installed RabbitMQ package (deb)
shell: |
dpkg -l | grep rabbitmq-server
failed_when: false
register: installed_rabbitmq
register: installed_rabbitmq_deb
when:
- not rabbitmq_upgrade | bool
- ansible_pkg_mgr == 'apt'
tags:
- rabbitmq-package-deb
- rabbitmq-apt-packages
- name: Get version of installed RabbitMQ package (rpm)
shell: |
rpm -qa | grep rabbitmq-server
failed_when: false
register: installed_rabbitmq_rpm
when:
- not rabbitmq_upgrade | bool
- ansible_pkg_mgr == 'yum'
tags:
- rabbitmq-package-rpm
- rabbitmq-apt-packages
- name: Register a fact for the installed RabbitMQ version
set_fact:
installed_rabbitmq: "{{ item }}"
when: not item | skipped and item | changed
with_items:
- "{{ installed_rabbitmq_deb }}"
- "{{ installed_rabbitmq_rpm }}"
- name: Compare installed version of RabbitMQ with new version variable
fail:
msg: "To install a new major/minor version of RabbitMQ set '-e rabbitmq_upgrade=true'."
when: >
not rabbitmq_upgrade | bool and
installed_rabbitmq.rc == 0 and
installed_rabbitmq.stdout.split()[2] != rabbitmq_package_version
when:
- not rabbitmq_upgrade | bool
- installed_rabbitmq.rc == 0
- not installed_rabbitmq.stdout | search(rabbitmq_package_version)
tags:
- rabbitmq-package-deb
- rabbitmq-package-rpm
- rabbitmq-apt-packages
- include: rabbitmq_upgrade_prep.yml

View File

@ -13,7 +13,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.
container_name: "{{ inventory_hostname }}"
container_networks:
management_address:

View File

@ -15,7 +15,6 @@
- name: Create test containers
hosts: all_containers
connection: local
gather_facts: false
pre_tasks:
- name: Destroy test containers
@ -40,7 +39,6 @@
- container-directories
roles:
- role: "lxc_container_create"
lxc_container_release: trusty
lxc_container_backing_store: dir
global_environment_variables:
PATH: "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

View File

@ -20,6 +20,13 @@
- name: Ensure apt cache is always refreshed
apt:
update_cache: yes
when: ansible_pkg_mgr == 'apt'
- name: Ensure yum packages are up to date
yum:
name: '*'
state: latest
update_cache: yes
when: ansible_pkg_mgr == 'yum'
- name: Ensure root's new public ssh key is in authorized_keys
authorized_key:
user: root
@ -31,20 +38,31 @@
stat:
path: /etc/nodepool/provider
register: nodepool
- name: Set the files to copy into the container cache for OpenStack-CI instances
- name: Set the files to copy into the container cache for OpenStack-CI instances (deb)
set_fact:
lxc_container_cache_files:
- { src: '/etc/pip.conf', dest: '/etc/pip.conf' }
- { src: '/etc/apt/apt.conf.d/99unauthenticated', dest: '/etc/apt/apt.conf.d/99unauthenticated' }
when: nodepool.stat.exists | bool
when:
- nodepool.stat.exists | bool
- ansible_pkg_mgr == 'apt'
- name: Set the files to copy into the container cache for OpenStack-CI instances (rhel)
set_fact:
lxc_container_cache_files:
- { src: '/etc/pip.conf', dest: '/etc/pip.conf' }
when:
- nodepool.stat.exists | bool
- ansible_pkg_mgr == 'yum'
- name: Determine the existing Ubuntu repo configuration
shell: 'awk "/^deb .*ubuntu\/? {{ ansible_distribution_release }} main/ {print \$2; exit}" /etc/apt/sources.list'
register: ubuntu_repo
changed_when: false
when: ansible_pkg_mgr == 'apt'
- name: Set apt repo facts based on discovered information
set_fact:
lxc_container_template_main_apt_repo: "{{ ubuntu_repo.stdout }}"
lxc_container_template_security_apt_rep: "{{ ubuntu_repo.stdout }}"
when: ansible_pkg_mgr == 'apt'
roles:
- role: "lxc_hosts"
lxc_net_address: 10.100.100.1
@ -52,8 +70,3 @@
lxc_net_bridge: lxcbr0
lxc_kernel_options:
- { key: 'fs.inotify.max_user_instances', value: 1024 }
lxc_container_caches:
- url: "https://rpc-repo.rackspace.com/container_images/rpc-trusty-container.tgz"
name: "trusty.tgz"
sha256sum: "56c6a6e132ea7d10be2f3e8104f47136ccf408b30e362133f0dc4a0a9adb4d0c"
chroot_path: trusty/rootfs-amd64

View File

@ -1,5 +1,5 @@
---
# Copyright 2015, 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.
@ -64,4 +64,4 @@
- hostvars['container1']['rabbitmq_ssl_key_checksum'] == hostvars['container2']['rabbitmq_ssl_key_checksum'] == hostvars['container3']['rabbitmq_ssl_key_checksum']
- name: Ensure expected version of rabbitmq is running
assert:
that: rabbitmqctl_status.stdout | search ("rabbit,\"RabbitMQ\",\"{{ rabbitmq_package_version.split('-')[0] }}\"")
that: rabbitmqctl_status.stdout | search ("rabbit,\"RabbitMQ\",\"{{ rabbitmq_release_version }}\"")

View File

@ -1,3 +1,11 @@
rabbitmq_cookie_token: secrete
rabbitmq_ssl_cert: /etc/rabbitmq/rabbitmq.pem
rabbitmq_ssl_key: /etc/rabbitmq/rabbitmq.key
rabbitmq_old_package:
debian:
rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server_3.5.7-1_all.deb"
rabbitmq_package_sha256: "b8a42321c2f2689dc579911fbb583bd9c4d2ce2f20003d7050d5a324a6d2de42"
redhat:
rabbitmq_package_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server-3.5.7-1.noarch.rpm"
rabbitmq_package_sha256: "5469b049d6444d95d917634da1e167cb678060920faec606788804a63356ba40"

View File

@ -26,9 +26,9 @@
- include: test-install-rabbitmq-server.yml
# Run tests
- include: test-functional.yml
- include: test-rabbitmq-server-functional.yml
vars:
rabbitmq_package_version: "3.6.1-1"
rabbitmq_release_version: "3.6.1"
############################# UPGRADE TESTING #############################
@ -38,14 +38,13 @@
# Install previous version of RabbitMQ server
- include: test-install-rabbitmq-server.yml
vars:
rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server_3.5.7-1_all.deb"
rabbitmq_package_version: "{{ rabbitmq_package_url.split('/')[-1].split('_')[1] }}"
rabbitmq_package_sha256: "b8a42321c2f2689dc579911fbb583bd9c4d2ce2f20003d7050d5a324a6d2de42"
rabbitmq_package_url: "{{ rabbitmq_old_package[ansible_os_family | lower]['rabbitmq_package_url'] }}"
rabbitmq_package_sha256: "{{ rabbitmq_old_package[ansible_os_family | lower]['rabbitmq_package_sha256'] }}"
# Run tests
- include: test-functional.yml
- include: test-rabbitmq-server-functional.yml
vars:
rabbitmq_package_version: "3.5.7-1"
rabbitmq_release_version: "3.5.7"
# Perform upgrade of RabbitMQ server (package_version will come
# from role defaults)
@ -54,6 +53,6 @@
rabbitmq_upgrade: true
# Run tests
- include: test-functional.yml
- include: test-rabbitmq-server-functional.yml
vars:
rabbitmq_package_version: "3.6.1-1"
rabbitmq_release_version: "3.6.1"

17
tests/vars/debian.yml Normal file
View File

@ -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.
rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server_3.5.7-1_all.deb"
rabbitmq_package_sha256: "b8a42321c2f2689dc579911fbb583bd9c4d2ce2f20003d7050d5a324a6d2de42"

17
tests/vars/redhat.yml Normal file
View File

@ -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.
rabbitmq_package_url: "http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.7/rabbitmq-server-3.5.7-1.noarch.rpm"
rabbitmq_package_sha256: "5469b049d6444d95d917634da1e167cb678060920faec606788804a63356ba40"

25
vars/debian.yml Normal file
View File

@ -0,0 +1,25 @@
---
# 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.
_rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server_3.6.1-1_all.deb"
_rabbitmq_package_version: "{{ rabbitmq_package_url.split('/')[-1].split('_')[1] }}"
_rabbitmq_release_version: "{{ rabbitmq_package_version.split('-')[0] }}"
_rabbitmq_package_sha256: "0728fbdb14ec62712c6f931a7d91648cafbc6c30d8d4da790832e784b4d2e956"
_rabbitmq_package_path: "/opt/rabbitmq-server.deb"
rabbitmq_dependencies:
- erlang-nox
- gcc
- python-dev

26
vars/redhat.yml Normal file
View File

@ -0,0 +1,26 @@
---
# 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.
_rabbitmq_package_url: "https://www.rabbitmq.com/releases/rabbitmq-server/v3.6.1/rabbitmq-server-3.6.1-1.noarch.rpm"
_rabbitmq_package_version: "{{ rabbitmq_package_url.split('/')[-1].rsplit('.', 1)[0] }}"
_rabbitmq_release_version: "{{ rabbitmq_package_version.split('-')[2] }}"
_rabbitmq_package_sha256: "b688950915289a8596bdce35086b00ad08ee0e32567396c5bda850854642fac7"
_rabbitmq_package_path: "/opt/rabbitmq-server.rpm"
rabbitmq_dependencies:
- erlang
- gcc
- openssl
- python-devel