Skip to content
This repository was archived by the owner on Jun 24, 2022. It is now read-only.

Fix versionlock centos 8 #797

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
10 changes: 5 additions & 5 deletions tasks/elasticsearch-RedHat-version-lock.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
- name: RedHat - install yum-version-lock
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yum-version-lock should also be replaced here with {{ versionlock_plugin_package }}.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, fixed

become: yes
yum:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this then better be package to be more generic?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also sensible

name: yum-plugin-versionlock
name: "{{ versionlock_plugin_package }}"
state: present
update_cache: yes

- name: RedHat - check if requested elasticsearch version lock exists
become: yes
shell: 'yum versionlock list | grep {{es_package_name}} | grep -c "{{es_version}}"'
shell: '{{ package_manager }} versionlock list | grep {{ es_package_name }} | grep -c "{{ es_version }}"'
register: es_requested_version_locked
args:
warn: false
Expand All @@ -18,7 +18,7 @@

- name: RedHat - lock elasticsearch version
become: yes
shell: yum versionlock delete 0:elasticsearch* ; yum versionlock add {{ es_package_name }}-{{ es_version }}
command: '"{{ package_manager }}" versionlock delete 0:elasticsearch* ; "{{ package_manager }}" versionlock add {{ es_package_name }}-{{ es_version }}'
args:
warn: false
when:
Expand All @@ -28,7 +28,7 @@

- name: RedHat - check if any elasticsearch version lock exists
become: yes
shell: yum versionlock list | grep -c elasticsearch
shell: '"{{ package_manager }}" versionlock list | grep -c elasticsearch'
register: es_version_locked
args:
warn: false
Expand All @@ -38,7 +38,7 @@

- name: RedHat - unlock elasticsearch version
become: yes
shell: yum versionlock delete 0:elasticsearch*
shell: '"{{ package_manager }}" versionlock delete 0:elasticsearch*'
args:
warn: false
when:
Expand Down
2 changes: 2 additions & 0 deletions vars/RedHat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
java: "{{ es_java | default('java-1.8.0-openjdk.x86_64') }}"
default_file: "/etc/sysconfig/elasticsearch"
es_home: "/usr/share/elasticsearch"
package_manager: "{% if ansible_os_family == 'RedHat' and ansible_distribution_major_version >= '8' %}dnf{% else %}yum{% endif %}"
Copy link
Contributor

@darxriggs darxriggs Oct 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better use ansible_distribution_major_version | int >= 8 or ansible_distribution_version is version('8', '>=') because for higher version numbers this comparison is not returning the expected result, e.g. '10' >= '8' evaluates to false.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ansible_os_family should not be required here because this file is only included in tasks/main.yml using ansible_os_family to derive the filename.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I primarily didn't want to diverge too far from existing statements in e.g. Debian.yml which has the same unnecessary check. But I'll remove it here as it's been discussed (I'm leaving it in Debian.yml for now though as I haven't tested there)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I've just removed all that and gone with ansible_facts.pkg_mgr to simplify things.

versionlock_plugin_package: "{% if ansible_os_family == 'RedHat' and ansible_distribution_major_version >= '8' %}python3-dnf-plugin-versionlock{% else %}yum-plugin-versionlock{% endif %}"