Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code for automatic updates #250

Merged
merged 73 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
4de663f
Add code for automatic updates
xtruthx Aug 30, 2023
b9e204d
Start changing playbook into taskfile
xtruthx Jan 16, 2024
eefcef9
Add note about modifications by NPS
widhalmt Jan 16, 2024
9570a9f
Move global vars to new role
widhalmt Jan 16, 2024
c79beb4
Merge branch 'main' into feature/update-216
widhalmt Jan 16, 2024
6a11bf5
Fix lint in defaults
widhalmt Jan 16, 2024
df106c5
lint
widhalmt Jan 16, 2024
6f97e74
Clean up lint
xtruthx Jan 16, 2024
1b47673
Move OS specific vars to global role
widhalmt Jan 16, 2024
0ae36bb
Fix lint
widhalmt Jan 16, 2024
839e603
Set default for elasticstack_ca_will_expire_soon
widhalmt Jan 16, 2024
91d588b
Move elasticsearch_ca naming to global role
widhalmt Jan 16, 2024
e7a4f35
Set name of Elasticsearch CA
widhalmt Jan 16, 2024
4f07aeb
Fix defaults for global role
widhalmt Jan 16, 2024
19367c9
Skip global role if it ran already
widhalmt Jan 16, 2024
61ff0a1
Stupid logical mistake
widhalmt Jan 17, 2024
931d6d1
Set version of ES on elasticstack_ca as target for all components
widhalmt Jan 17, 2024
c162010
Rename file for naming scheme
widhalmt Jan 17, 2024
2b365d0
Lint
widhalmt Jan 17, 2024
ec218de
Specify subvariable for checking
widhalmt Jan 17, 2024
7bebba7
Remove reboot part of upgrade playbook
widhalmt Jan 17, 2024
e49d50b
Add note about version detection
widhalmt Jan 17, 2024
ff13c9e
Remove obsolete vars directory from repos
widhalmt Jan 17, 2024
1cdb583
Use module instead of shell
widhalmt Jan 17, 2024
b94c2cc
Remove overly complicated version check
widhalmt Jan 17, 2024
00a4fcf
Call upgrade taskfile when new version > current version
widhalmt Jan 17, 2024
0017987
Remove upgrades for other packages
widhalmt Jan 18, 2024
464b663
Upgrade shutdown nodes right away
widhalmt Jan 18, 2024
242276d
Only start Elasticsearch if it was running before
widhalmt Jan 18, 2024
1f463da
Remove redundant become
widhalmt Jan 18, 2024
b248e08
Restrict execution of upgrade playbook to one at a time
widhalmt Jan 18, 2024
b215d31
Fetch elastic password for upgrades
widhalmt Jan 18, 2024
dad70f6
Merge branch 'main' into feature/update-216
widhalmt Jan 19, 2024
5244078
Replace package installation with more general one
widhalmt Jan 19, 2024
c659dee
Fix some errors in variable names
widhalmt Jan 19, 2024
d1d0e2d
Damn typo
widhalmt Jan 19, 2024
1cb7571
Directly upgrade nodes that are down
widhalmt Jan 19, 2024
2865d5d
Apply workaround for seria in include tasks
widhalmt Feb 12, 2024
7c4b38d
Workaround for "back in cluster" check
widhalmt Feb 12, 2024
49b34d4
Fix typo
widhalmt Feb 13, 2024
55e5de4
Introduce (and set) elasticsearch_nodename variable
widhalmt Feb 13, 2024
5d92f58
Add rolling restart for handler
widhalmt Feb 13, 2024
5eef485
Merge branch 'main' into feature/update-216
widhalmt Feb 13, 2024
07bc9e4
Enable shard allocation before checks
widhalmt Feb 13, 2024
9ae5b16
Re-Add repo key
widhalmt Feb 13, 2024
96eb6fc
Restart all applications after upgrade
widhalmt Feb 13, 2024
a257c56
Build Logstash version different for deb
widhalmt Feb 13, 2024
b7edd49
Typo
widhalmt Feb 13, 2024
0ce2cda
Typo
widhalmt Feb 13, 2024
1d1537d
NGAH
widhalmt Feb 13, 2024
4b08e54
Revert prototype for rolling restart
widhalmt Feb 14, 2024
4f2e7a0
Test old version picking system
widhalmt Feb 14, 2024
d1d5caf
Fix package name creation on .deb
widhalmt Feb 15, 2024
76f271c
Typo
widhalmt Feb 15, 2024
c098870
Remove directive we don't need anymore
widhalmt Feb 15, 2024
506aa6d
Handle single instances of Elasticsearch during update
widhalmt Feb 15, 2024
2a659ff
Lint
widhalmt Feb 15, 2024
ff70c58
Enable repo only with rpm and full_stack
widhalmt Feb 15, 2024
dde6c86
Streamline installation of common packages and dependencies
widhalmt Feb 15, 2024
3f9f6f4
Add a few explanatory comments
widhalmt Feb 15, 2024
35e31c1
Update Readme
widhalmt Feb 15, 2024
e021ccb
Merge branch 'main' into feature/update-216
widhalmt Feb 16, 2024
83243b3
Update sponsoring note
widhalmt Feb 17, 2024
a728f62
Make single update a block
widhalmt Mar 8, 2024
e28c823
Match elasticsearch_api_host with rest of code
widhalmt Mar 8, 2024
3d0787c
Add faster upgrades for non-prod clusters
widhalmt Mar 8, 2024
7bc3a0b
Lint
widhalmt Mar 8, 2024
df5ba99
Merge branch 'feature/update-216' of github.com:NETWAYS/ansible-colle…
widhalmt Mar 22, 2024
31089d9
Make docs about nodename more clear
widhalmt Mar 22, 2024
53a65b3
Be more clear about Installation task
widhalmt Mar 22, 2024
d2b7458
A bit more clarification
widhalmt Mar 22, 2024
b7d7186
Merge branch 'main' into feature/update-216
widhalmt Apr 17, 2024
a3d021e
Fix remaining legacy group names
widhalmt Apr 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NOTICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

Here's a list of sponsors who contributed by having the collection improved via outsourcing to NETWAYS.

* CID GmbH : Thank you so much for sponsoring. Especially the feature to have different types of Elasticsearch nodes in the cluster.
* CID GmbH : Thank you so much for sponsoring. Especially the feature to have different types of Elasticsearch nodes in the cluster and the ingetration of rolling upgrades.
16 changes: 12 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ You will want to have reliable DNS resolution or enter all hosts of the stack in

The variable `elasticstack_no_log` can be set to `false` if you want to see the output of all tasks. It defaults to `true` because some tasks could reveal passwords in production.

### Versioning
### Versions and upgrades

*elasticstack_version*: Version number of tools to install. Only set if you don't want the latest. (default: none).
*elasticstack_version*: Version number of tools to install. Only set if you don't want the latest on new setups. (default: none). If you already have an installation of Elastic Stack, this collection will query the version of Elasticsearch on the CA host and use it for all further installations in the same setup. (Only if you run the `elasticsearch` role before all others) Example: `7.17.2`

*elasticstack_release*: Major release version of Elastic stack to configure. (default: `7`)
*elasticstack_release*: Major release version of Elastic stack to configure. (default: `7`) Make sure it corresponds to `elasticstack_version` if you set both.

For OSS version see `elasticstack_variant` below. **IMPORTANT** Do not change the version once you have set up the stack. There are unpredictable effects to be expected when using this for upgrades. And upgrade mechanism is already on it's way. (default: none. Example: `7.17.2`)
For OSS version see `elasticstack_variant` below.

*elasticstack_variant*: Variant of the stack to install. Valid values: `elastic` or `oss`. (default: `elastic`)

Expand All @@ -99,6 +99,14 @@ roles:
elasticstack_version: 8.8.1
```
#### Upgrades ####
Set `elasticstack_version` to the version you want to upgrade to. Positively do read and understand Elastics changelog and "breaking changes" of your target version and all between your current and the target version. Do not use unless you have a valid backup.

If an upgrade fails, you can try re-running the collection with the same settings. There are several tasks that can provide "self-healing". Please do not rely on these mechanisms, they are more of a "convenience recovery" for easier steps.

The collection will make sure to upgrade Elasticsearch nodes one by one.

### Default Passwords

Default passwords can be seen during generation, or found later in `/usr/share/elasticsearch/initial_passwords`
Expand Down
5 changes: 5 additions & 0 deletions docs/role-elasticsearch.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Role Variables
--------------

* *elasticsearch_node_types*: List of types of this very node. Please refer to [official docs](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-node.html) for details. (default: not set. allowed value: array of types)
+ *elasticsearch_nodename*': Node name of the Elasticsearch node. (default: value of `ansible_hostname`)
* *elasticsearch_clustername*: Name the Elasticsearch Cluster (default: `elasticsearch`)
* *elasticsearch_heap*: Heapsize for Elasticsearch. (Half of free memory on host. Maximum 30GB. (default: Half of hosts memory. Min 1GB, Max 30GB)
* *elasticsearch_tls_key_passphrase*: Passphrase for elasticsearch certificates (default: `PleaseChangeMeIndividually`)
Expand Down Expand Up @@ -53,6 +54,10 @@ This variable activates a workaround to start on systems that have certain harde
* *elasticsearch_seed_hosts*: Set elasticsearch seed hosts
* *elasticsearch_security_enrollment*: Controls enrollment (of nodes and Kibana) to a local node that’s been autoconfigured for security.

The following variable was only integrated to speed up upgrades of non-production clusters. Use with caution and at your own risk:

* *elasticsearch_unsafe_upgrade_restart*: This will still perform rolling upgrades, but will first update the package and then restart the service. In contrast the default behaviour is to stop the service, do the upgrade and then start again. (default: `false`)

These variables are identical over all our elastic related roles, hence the different naming schemes.

* *elasticstack_ca*: Set to the inventory hostname of the host that should house the CA for certificates for inter-node communication. (default: First node in the `elasticsearch` host group)
Expand Down
1 change: 0 additions & 1 deletion molecule/elasticstack_default/verify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,3 @@
success_msg: "'{{ item }}' was found in nodes.content"
with_inventory_hostnames: all
when: groups[elasticstack_elasticsearch_group_name] | length > 1

18 changes: 0 additions & 18 deletions roles/beats/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ beats_auditbeat: false
beats_metricbeat: false
beats_target_hosts:
- localhost
elasticstack_beats_port: 5044
beats_logging: file
beats_logpath: /var/log/beats
beats_loglevel: info
Expand Down Expand Up @@ -58,23 +57,6 @@ beats_metricbeat_modules:
- system
beats_metricbeat_loadbalance: true

elasticstack_release: 8
elasticstack_full_stack: true
elasticstack_variant: elastic
elasticstack_security: true

elasticstack_elasticsearch_group_name: elasticsearch
elasticstack_logstash_group_name: logstash

elasticstack_ca_dir: /opt/es-ca
elasticstack_ca_pass: PleaseChangeMe
elasticstack_initial_passwords: /usr/share/elasticsearch/initial_passwords
elasticstack_elasticsearch_http_port: 9200
elasticstack_no_log: true
beats_cert_validity_period: 1095
beats_cert_expiration_buffer: "+30d"
beats_cert_will_expire_soon: false

# Variables for debugging and development

elasticstack_override_beats_tls: false
6 changes: 6 additions & 0 deletions roles/beats/tasks/auditbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@
name: "{{ beats_auditbeat_package }}"
enablerepo:
- 'elastic-{{ elasticstack_release }}.x'
notify:
- Restart Auditbeat
when:
- ansible_os_family == "RedHat"
- elasticstack_full_stack | bool

- name: Install Auditbeat - rpm - standalone
ansible.builtin.package:
name: "{{ beats_auditbeat_package }}"
notify:
- Restart Auditbeat
when:
- ansible_os_family == "RedHat"
- not elasticstack_full_stack | bool

- name: Install Auditbeat - deb
ansible.builtin.package:
name: "{{ beats_auditbeat_package }}"
notify:
- Restart Auditbeat
when:
- ansible_os_family == "Debian"

Expand Down
12 changes: 0 additions & 12 deletions roles/beats/tasks/beats-security.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
---

- name: Install packages for security tasks
ansible.builtin.package:
name:
- unzip
- python3-cryptography
- openssl
tags:
- certificates
- renew_ca
- renew_kibana_cert
- renew_beats_cert

- name: Ensure beats certificate exists
ansible.builtin.stat:
path: "/etc/beats/certs/{{ inventory_hostname }}-beats.crt"
Expand Down
6 changes: 6 additions & 0 deletions roles/beats/tasks/filebeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,26 @@
name: "{{ beats_filebeat_package }}"
enablerepo:
- 'elastic-{{ elasticstack_release }}.x'
notify:
- Restart Filebeat
when:
- ansible_os_family == "RedHat"
- elasticstack_full_stack | bool

- name: Install Filebeat - rpm - standalone
ansible.builtin.package:
name: "{{ beats_filebeat_package }}"
notify:
- Restart Filebeat
when:
- ansible_os_family == "RedHat"
- not elasticstack_full_stack | bool

- name: Install Filebeat - deb
ansible.builtin.package:
name: "{{ beats_filebeat_package }}"
notify:
- Restart Filebeat
when:
- ansible_os_family == "Debian"

Expand Down
20 changes: 3 additions & 17 deletions roles/beats/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
---

- name: Include OS specific vars
ansible.builtin.include_vars: '{{ item }}'
with_first_found:
- '{{ ansible_os_family }}_{{ ansible_distribution_major_version }}.yml'
- '{{ ansible_os_family }}.yml'
- name: Include global role
ansible.builtin.import_role:
name: netways.elasticstack.elasticstack

- name: Update apt cache.
ansible.builtin.apt:
Expand All @@ -25,18 +23,6 @@
- elasticstack_variant != "oss"
- not elasticstack_override_beats_tls | bool

- name: Set elasticstack_ca variable if not already done by user
ansible.builtin.set_fact:
elasticstack_ca: "{{ groups[elasticstack_elasticsearch_group_name][0] }}"
when:
- beats_security | bool
- elasticstack_ca is undefined
- groups[elasticstack_elasticsearch_group_name] is defined
tags:
- certificates
- renew_ca
- renew_beats_cert

- name: Set beats_ca_dir if whole stack is used
ansible.builtin.set_fact:
beats_ca_dir: "/etc/beats/certs"
Expand Down
6 changes: 6 additions & 0 deletions roles/beats/tasks/metricbeat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@
name: "{{ beats_metricbeat_package }}"
enablerepo:
- 'elastic-{{ elasticstack_release }}.x'
notify:
- Restart Metricbeat
when:
- ansible_os_family == "RedHat"
- elasticstack_full_stack | bool

- name: Install Metricbeat - rpm - standalone
ansible.builtin.package:
name: "{{ beats_metricbeat_package }}"
notify:
- Restart Metricbeat
when:
- ansible_os_family == "RedHat"
- not elasticstack_full_stack | bool

- name: Install Metricbeat - deb
ansible.builtin.package:
name: "{{ beats_metricbeat_package }}"
notify:
- Restart Metricbeat
when:
- ansible_os_family == "Debian"

Expand Down
4 changes: 0 additions & 4 deletions roles/beats/vars/Debian.yml

This file was deleted.

4 changes: 0 additions & 4 deletions roles/beats/vars/RedHat.yml

This file was deleted.

2 changes: 0 additions & 2 deletions roles/beats/vars/main.yml

This file was deleted.

27 changes: 3 additions & 24 deletions roles/elasticsearch/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,39 +31,18 @@ elasticsearch_heap_dump_path: "/var/lib/elasticsearch"

elasticsearch_jna_workaround: false

# The following variables are to be used when activating security
# They follow a different naming scheme to show that they are global
# to our set of Elastic Stack related Ansible roles

# elasticstack_ca: First host in the `elasticsearch` group
elasticstack_ca_dir: /opt/es-ca
elasticstack_initial_passwords: /usr/share/elasticsearch/initial_passwords
elasticsearch_initialized_file: "{{ elasticstack_initial_passwords | dirname }}/cluster_initialized"
elasticstack_ca_name: "CN=Elastic Certificate Tool Autogenerated CA"
elasticstack_ca_pass: PleaseChangeMe
elasticstack_ca_validity_period: 1095
elasticsearch_tls_key_passphrase: PleaseChangeMeIndividually
elasticsearch_cert_validity_period: 1095
elasticstack_ca_expiration_buffer: 30
elasticsearch_cert_expiration_buffer: 30
elasticstack_ca_will_expire_soon: false
elasticsearch_cert_will_expire_soon: false
elasticsearch_ssl_verification_mode: full

# use this only for non-prod environments and at your own risk!
elasticsearch_unsafe_upgrade_restart: false

# only used internally
elasticsearch_freshstart:
changed: false
elasticsearch_freshstart_security:
changed: false

# "global" variables for all roles

elasticstack_release: 8
elasticstack_full_stack: true
elasticstack_variant: elastic
elasticstack_elasticsearch_http_port: 9200
elasticstack_no_log: true

elasticstack_elasticsearch_group_name: elasticsearch
elasticstack_logstash_group_name: logstash
elasticstack_kibana_group_name: kibana
Loading