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

(Re-)start service with notify #3

Merged
merged 2 commits into from
Mar 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ This role supports the following,
- Defaults to `127.0.0.1`.
- `opensearch_api_port`
- Defaults to `9200`.
- `opencast_opensearch_started`
- By default, the OpenSearch service will (re)start if something has changed that requires the service to be restarted. This is done via the Ansible notification handler. However, if you expect the OpenSearch service to be running when you run this role, you can force the service to start by setting the value to `true`.
- Defaults to `false` (make use of Ansible Handler to reach the state)

## Dependencies

Expand Down
3 changes: 3 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ opensearch_api_host: 127.0.0.1

# Bind OpenSearch to this specific port.
opensearch_api_port: 9200

# Whether to force the start of the OpenSearch service at the end of this role.
opencast_opensearch_started: false
7 changes: 6 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
- name: Include opensearch installation
ansible.builtin.import_tasks: opensearch.yml

- name: Start and enable OpenSearch service
- name: Enable OpenSearch service
ansible.builtin.systemd:
name: opensearch
enabled: true

- name: Start OpenSearch service
ansible.builtin.systemd:
name: opensearch
state: started
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing this means that if I go to my OpenSearch server run systemctl stop opensearch and later run this role to ensure everything is set up correctly, OpenSearch will not be started. That probably shouldn't be.

when: opencast_opensearch_started | bool
2 changes: 2 additions & 0 deletions tasks/opensearch.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
---
- name: OpenSearch Install on Debian
notify: Restart opensearch
ansible.builtin.apt:
name:
- opensearch
Expand All @@ -9,6 +10,7 @@
when: ansible_os_family == 'Debian'

- name: OpenSearch Install on EL
notify: Restart opensearch
ansible.builtin.dnf:
name:
- opensearch
Expand Down