Skip to content

Use the systemd module to reload systemd instead of ansible.builtin.command - #215

Open
gohri81-tech wants to merge 1 commit into
opensearch-project:mainfrom
gohri81-tech:patch-1
Open

gohri81-tech wants to merge 1 commit into
opensearch-project:mainfrom
gohri81-tech:patch-1

Conversation

@gohri81-tech

Copy link
Copy Markdown

Description

Closes #207.

The reload systemd configuration handler in roles/linux/opensearch/handlers/main.yml shelled out to systemctl daemon-reload with ansible.builtin.command. Using the module instead means the task no longer reports changed on every run, works under --check, and no longer needs a command/shell exception from ansible-lint. ansible.builtin.systemd is already used by the restart opensearch handler directly below, so this keeps the file consistent with itself rather than introducing a new module.

- name: reload systemd configuration
  become: true
  ansible.builtin.systemd:
    daemon_reload: true

The issue suggested folding the reload into a single restart opensearch handler with daemon_reload: yes. I kept the two handlers separate on purpose, because tasks notify reload systemd configuration on its own and merging them would restart the service in cases where only a unit file changed.

I used ansible.builtin.systemd rather than the newer ansible.builtin.systemd_service name so that the role keeps working on ansible-core versions older than 2.16. Happy to switch if you would rather move to the new name.

Issues Resolved

Closes #207

Check List

  • Commits are signed per the DCO using --signoff

I don't have an environment here to run the playbook against a real host, so please treat CI and your own run as the source of truth.

The handler shelled out to systemctl daemon-reload through
ansible.builtin.command, which always reports changed and cannot run in
check mode. ansible.builtin.systemd with daemon_reload does the same work
as a module, and the module is already used by the restart handler right
below it.

The two handlers are left separate because tasks notify them
independently.

Closes opensearch-project#207

Signed-off-by: Gaurav K Ohri <gohri81@gmail.com>
@gohri81-tech

Copy link
Copy Markdown
Author

A gentle reminder on this one whenever someone has time. It replaces the ansible.builtin.command call to reload systemd with the systemd module's own daemon_reload, so the task stops being flagged by ansible-lint and becomes idempotent.

Happy to adjust it if you would prefer a different shape. Thank you.

@gohri81-tech

Copy link
Copy Markdown
Author

Gentle nudge - no review since this was opened on 17 September. It swaps the ansible.builtin.command call for the systemd module's own daemon_reload, so the handler becomes idempotent and works under --check (closes the linked issue). The one red check is the merit-badger action, not the change itself. Could a code owner take a look? Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

Don't use ansible.builtin.command to reload systemd

1 participant