openstack-ansible-rabbitmq_.../tasks/rabbitmq_upgrade_check.yml
Dmitriy Rabotyagov dceda157fa Replace shell with simple command for version verification
There is no need in using complicated shell for getting/grepping
for instaled rabbitmq version as this can be done in more neat way
with simple commad.

Alternative would be to gather package facts, but we may want not to
rely on facts caching and leave quering package managers.

Change-Id: Ieb858a7e850ec6b48989196392fb85a4b3c2a8a7
2022-04-13 11:43:08 +00:00

82 lines
2.4 KiB
YAML

---
# Copyright 2015, 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.
# ansible-lint fails on this task due to the detected use of 'dpkg',
# so we skip this task in the ansible-lint check by using the
# 'skip_ansible_lint' tag
- name: Get version of installed RabbitMQ package (deb)
command: "dpkg-query -W rabbitmq-server"
changed_when: false
check_mode: false
failed_when: false
register: installed_rabbitmq_deb
when:
- not rabbitmq_upgrade | bool
- ansible_facts['pkg_mgr'] == 'apt'
tags:
- rabbitmq-package-deb
- rabbitmq-apt-packages
- skip_ansible_lint
# ansible-lint fails on this task due to the detected use of 'rpm',
# so we skip this task in the ansible-lint check by using the
# 'skip_ansible_lint' tag
- name: Get version of installed RabbitMQ package (rpm)
command: "rpm -q rabbitmq-server"
args:
warn: no
changed_when: false
check_mode: false
failed_when: false
register: installed_rabbitmq_rpm
when:
- not rabbitmq_upgrade | bool
- ansible_facts['pkg_mgr'] == 'dnf'
tags:
- rabbitmq-package-rpm
- rabbitmq-dnf-packages
- skip_ansible_lint
- name: Register a fact for the installed RabbitMQ version
set_fact:
installed_rabbitmq: "{{ item }}"
when:
- item is not skipped
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
- installed_rabbitmq.rc == 0
- not installed_rabbitmq.stdout is search(rabbitmq_package_version)
- rabbitmq_install_method != 'distro'
tags:
- rabbitmq-package-deb
- rabbitmq-package-rpm
- rabbitmq-apt-packages
- include_tasks: rabbitmq_upgrade_prep.yml
args:
apply:
tags:
- rabbitmq-upgrade
when: rabbitmq_upgrade | bool
tags:
- always