|
1 |
| -- when: ansible_os_family == 'Debian' |
2 |
| - block: |
3 |
| - - name: Add Elastic repository key |
4 |
| - apt_key: |
5 |
| - url: "{{ elasticsearch.repository.apt.key_url }}" |
| 1 | +--- |
| 2 | +- name: Install python3-debian package with apt |
| 3 | + ansible.builtin.apt: |
| 4 | + name: python3-debian |
| 5 | + update_cache: yes |
6 | 6 |
|
7 |
| - - name: Add Elastic repository |
8 |
| - loop: |
9 |
| - - /etc/apt/sources.list.d/elastic.list |
10 |
| - copy: |
11 |
| - content: | |
12 |
| - {{ elasticsearch.repository.apt.repository }} |
13 |
| - dest: "{{ item }}" |
14 |
| - register: elasticsearch_add_apt_repository |
15 |
| - |
16 |
| - - name: Update apt cache |
17 |
| - when: elasticsearch_add_apt_repository.changed |
18 |
| - apt: |
19 |
| - update_cache: yes |
| 7 | +- name: Remove the legacy apt repository |
| 8 | + ansible.builtin.file: |
| 9 | + dest: /etc/apt/sources.list.d/elastic.list |
| 10 | + state: absent |
| 11 | + |
| 12 | +- name: Add the elasticsearch apt repository |
| 13 | + register: elasticsearch_repository_added |
| 14 | + ansible.builtin.deb822_repository: |
| 15 | + name: elastic |
| 16 | + uris: "{{ elasticsearch.repository.apt.repository }}" |
| 17 | + signed_by: "{{ elasticsearch.repository.apt.key_url }}" |
| 18 | + types: [deb] |
| 19 | + components: [main] |
| 20 | + suites: [stable] |
| 21 | + state: present |
| 22 | + enabled: yes |
20 | 23 |
|
21 |
| - - name: Install Elasticsearch |
22 |
| - apt: |
23 |
| - name: elasticsearch |
| 24 | +- name: Update apt cache |
| 25 | + when: elasticsearch_repository_added.changed |
| 26 | + ansible.builtin.apt: |
| 27 | + update_cache: yes |
24 | 28 |
|
25 |
| - - name: Restart Elasticsearch after package upgrade |
26 |
| - lineinfile: |
27 |
| - path: /etc/default/elasticsearch |
28 |
| - regexp: '^#?RESTART_ON_UPGRADE=' |
29 |
| - line: RESTART_ON_UPGRADE=true |
| 29 | +- name: Restart Elasticsearch after package upgrade |
| 30 | + lineinfile: |
| 31 | + path: /etc/default/elasticsearch |
| 32 | + regexp: '^#?RESTART_ON_UPGRADE=' |
| 33 | + line: RESTART_ON_UPGRADE=true |
30 | 34 |
|
31 |
| -- name: Enable Elasticsearch |
32 |
| - service: |
| 35 | +- name: Install Elasticsearch |
| 36 | + when: ansible_os_family == 'Debian' |
| 37 | + notify: Restart Elasticsearch |
| 38 | + ansible.builtin.apt: |
33 | 39 | name: elasticsearch
|
34 |
| - enabled: yes |
|
0 commit comments