This repository has been archived by the owner on Jun 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 855
/
Copy pathelasticsearch-Debian.yml
118 lines (101 loc) · 3.75 KB
/
elasticsearch-Debian.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
---
- name: set fact force_install to no
set_fact: force_install=no
- name: set fact force_install to yes
set_fact: force_install=yes
when: es_allow_downgrades
- 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 }}"
register: elasticsearch_package
failed_when: False
changed_when: False
check_mode: no
- name: unhold elasticsearch package when switching to a different package type
become: yes
dpkg_selections:
name: "{{ es_other_package_name }}"
selection: "install"
when: elasticsearch_package.stdout == 'install ok installed'
- name: stop elasticsearch
service:
name: 'elasticsearch'
state: stopped
when: elasticsearch_package.stdout == 'install ok installed'
- name: Debian - Remove elasticsearch package if we are switching to a different package type
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 }}'
id: '{{ es_apt_key_id }}'
state: present
when: es_add_repository and es_apt_key | string
- name: Debian - Add elasticsearch repository
apt_repository:
repo: '{{ item.repo }}'
state: '{{ item.state }}'
when: es_add_repository
with_items:
- { repo: "{{ es_apt_url_old }}", state: "absent" }
- { repo: "{{ es_apt_url }}", state: "present" }
- { repo: "{{ es_other_apt_url }}", state: "absent" }
- name: Include optional user and group creation.
when: (es_user_id is defined) and (es_group_id is defined)
include: elasticsearch-optional-user.yml
- name: Debian - Get installed elasticsearch version
command: dpkg-query --showformat='${Version}' --show {{ es_package_name }}
register: installed_es_version
failed_when: False
changed_when: False
check_mode: no
- name: Debian - unhold elasticsearch version
become: yes
dpkg_selections:
name: "{{ es_package_name }}"
selection: "install"
when: not es_version_lock or (installed_es_version.stdout and installed_es_version.stdout != es_version)
- name: Debian - Ensure elasticsearch is installed
become: yes
apt:
name: '{{ es_package_name }}{% if es_version is defined and es_version != "" %}={{ es_version }}{% endif %}'
state: present
force: '{{ force_install }}'
allow_unauthenticated: "{{ 'no' if es_apt_key else 'yes' }}"
cache_valid_time: 86400
when: es_use_repository
register: debian_elasticsearch_install_from_repo
notify: restart elasticsearch
environment:
ES_PATH_CONF: "{{ es_conf_dir }}"
- name: Debian - hold elasticsearch version
become: yes
dpkg_selections:
name: "{{ es_package_name }}"
selection: "hold"
when: es_version_lock
# workaround due to https://github.com/ansible/ansible/issues/66977
- set_fact:
es_deb_url: "{% if es_version is version('7.0.0', '>=') %}{{ es_package_url }}-{{ es_version }}-amd64.deb{% else %}{{ es_package_url }}-{{ es_version }}.deb{% endif %}"
- name: Debian - Install Elasticsearch from url
become: yes
apt:
deb: "{% if es_custom_package_url is defined %}{{ es_custom_package_url }}{% else %}{{ es_deb_url }}{% endif %}"
state: present
when: not es_use_repository
register: elasticsearch_install_from_package
notify: restart elasticsearch
environment:
ES_PATH_CONF: "{{ es_conf_dir }}"