Properly cleanup the other apt repository when switching packages

This commit is contained in:
Michael Russell 2019-01-02 10:39:48 +01:00
parent 5126dbc5e8
commit f7d402369c
No known key found for this signature in database
GPG key ID: A90C1696496085FE
2 changed files with 28 additions and 21 deletions

View file

@ -16,6 +16,7 @@
es_xpack_users_command: "elasticsearch-users"
es_other_package_name: "elasticsearch-oss"
es_other_repo_name: "{{ 'oss-' + es_major_version }}"
es_other_apt_url: "deb https://artifacts.elastic.co/packages/{{ 'oss-' + es_major_version }}/apt stable main"
- name: Detect if es_version is before X-Pack was open and included
set_fact:
@ -35,6 +36,7 @@
set_fact:
es_repo_name: "{{ 'oss-' + es_major_version }}"
es_other_repo_name: "{{ es_major_version }}"
es_other_apt_url: "deb https://artifacts.elastic.co/packages/{{ es_major_version }}/apt stable main"
es_package_name: "elasticsearch-oss"
es_other_package_name: "elasticsearch"
when:

View file

@ -7,26 +7,8 @@
set_fact: force_install=yes
when: es_allow_downgrades
- name: Debian - Install apt-transport-https to support https APT downloads
become: yes
apt: name=apt-transport-https state=present
when: es_use_repository
- name: Debian - Add Elasticsearch repository key
become: yes
apt_key: url="{{ es_apt_key }}" state=present
when: es_use_repository and es_apt_key
- name: Debian - Add elasticsearch repository
become: yes
apt_repository: repo={{ item.repo }} state={{ item.state}}
with_items:
- { repo: "{{ es_apt_url_old }}", state: "absent" }
- { repo: "{{ es_apt_url }}", state: "present" }
when: es_use_repository
- name: Gracefully stop and remove elasticsearch package if switching between OSS and standard
become: yes
block:
- name: Check if the elasticsearch package is installed
shell: "dpkg-query -W -f'${Status}' {{ es_other_package_name }}"
@ -35,20 +17,43 @@
changed_when: False
- name: stop elasticsearch
become: yes
service:
name: '{{ instance_init_script | basename }}'
state: stopped
when: elasticsearch_package.stdout == 'install ok installed'
- name: Debian - Remove elasticsearch package if we are switching to a different package type
become: yes
apt:
name: '{{ es_other_package_name }}'
state: absent
when: elasticsearch_package.stdout == 'install ok installed'
- name: Install Elasticsearch repository
when: es_use_repository
become: yes
block:
- name: Debian - Install apt-transport-https to support https APT downloads
apt:
name: apt-transport-https
state: present
- name: Debian - Add Elasticsearch repository key
apt_key:
url: '{{ es_apt_key }}'
state: present
when: es_apt_key is defined
- name: Debian - Add elasticsearch repository
apt_repository:
repo: '{{ item.repo }}'
state: '{{ item.state }}'
with_items:
- { repo: "{{ es_apt_url_old }}", state: "absent" }
- { repo: "{{ es_apt_url }}", state: "present" }
- { repo: "{{ es_other_apt_url }}", state: "absent" }
- name: Debian - Ensure elasticsearch is installed
become: yes
apt: