Skip to content

Commit 721b9d9

Browse files
committed
feat(roles/elasticsearch): add logrotate config for daily rotation
1 parent d5b6777 commit 721b9d9

5 files changed

Lines changed: 392 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717

1818
### Added
1919

20+
* **role:elasticsearch**: Add logrotate config for daily rotation
2021
* **role:freeipa_server**: Add the ability to specify the systemd unit start timeout
2122
* **role:postfix**: Add RHEL 10 support
2223
* **role:kvm_vm**: Add the ability to resize disks

roles/elasticsearch/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ ansible-playbook --inventory inventory linuxfabrik.lfops.elasticsearch --limit n
198198
| `elasticsearch__discovery_seed_hosts` | A list of IPs or hostnames that point to all master-eligible nodes of the cluster. The port defaults to 9300 but can be overwritten using `:9301`, for example. | unset |
199199
| `elasticsearch__http_cert` | ASCII-armored PEM HTTP certificate. | unset |
200200
| `elasticsearch__http_key` | ASCII-armored PEM HTTP private key. | unset |
201+
| `elasticsearch__log4j2_retention_days` | Number of days to retain rotated Elasticsearch log files (server, deprecation, slowlog, audit). All log appenders rotate daily and delete files older than this value. | `3` |
201202
| `elasticsearch__network_host` | Sets the address for both HTTP and transport traffic. Accepts an IP address, a hostname, or a [special value](https://www.elastic.co/guide/en/elasticsearch/reference/8.19/modules-network.html#network-interface-values). | `'_local_'` |
202203
| `elasticsearch__node_attributes` | Dictionary of custom node attributes. Can be used for shard allocation awareness. Each attribute identifies a node's physical location or characteristic. | `{}` |
203204
| `elasticsearch__node_name` | A descriptive name for the node | `'{{ ansible_facts["nodename"] }}'` |
@@ -230,6 +231,7 @@ elasticsearch__discovery_seed_hosts:
230231
- 'node3.example.com:9301'
231232
elasticsearch__http_cert: '{{ lookup("ansible.builtin.file", "{{ inventory_dir }}/host_files/{{ inventory_hostname }}/etc/elasticsearch/certs/http.crt") }}'
232233
elasticsearch__http_key: '{{ lookup("ansible.builtin.file", "{{ inventory_dir }}/host_files/{{ inventory_hostname }}/etc/elasticsearch/certs/http.key") }}'
234+
elasticsearch__log4j2_retention_days: 7
233235
elasticsearch__network_host: '0.0.0.0'
234236
elasticsearch__network_host: '_local_' # or '127.0.0.1' for single node
235237
elasticsearch__node_attributes:

roles/elasticsearch/defaults/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ elasticsearch__node_attributes: {}
2525
elasticsearch__node_name: '{{ ansible_facts["nodename"] }}'
2626
elasticsearch__path_data: '/var/lib/elasticsearch'
2727
elasticsearch__path_repos: []
28+
elasticsearch__log4j2_retention_days: 3
2829
elasticsearch__service_enabled: true
2930
elasticsearch__service_state: 'started'
3031

roles/elasticsearch/tasks/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@
117117
vars:
118118
shared__remove_rpmnew_rpmsave_config_file: '/etc/elasticsearch/elasticsearch.yml'
119119

120+
- name: 'deploy /etc/elasticsearch/log4j2.properties'
121+
ansible.builtin.template:
122+
src: 'etc/elasticsearch/log4j2.properties.j2'
123+
dest: '/etc/elasticsearch/log4j2.properties'
124+
owner: 'root'
125+
group: 'elasticsearch'
126+
mode: 0o660
127+
backup: true
128+
notify: 'elasticsearch: restart elasticsearch'
129+
130+
- name: 'Remove rpmnew / rpmsave (and Debian equivalents)'
131+
ansible.builtin.include_role:
132+
name: 'shared'
133+
tasks_from: 'remove-rpmnew-rpmsave.yml'
134+
vars:
135+
shared__remove_rpmnew_rpmsave_config_file: '/etc/elasticsearch/log4j2.properties'
136+
120137
- name: 'deploy {{ __elasticsearch__sysconfig_file_path }}'
121138
ansible.builtin.template:
122139
src: 'etc/sysconfig/elasticsearch.j2'

0 commit comments

Comments
 (0)