Skip to content

Commit

Permalink
Make sure to stop the service before removing the "state file"
Browse files Browse the repository at this point in the history
  • Loading branch information
tersmitten committed Jan 7, 2025
1 parent e0c16f8 commit 5ad1da3
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
8 changes: 7 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# handlers file
---
- name: restart service

Check warning on line 3 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.service:
name: "{{ snmpd_service_name }}"
state: stopped
listen: restart snmpd

- name: remove persistent data file

Check warning on line 9 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.file:
path: /var/lib/snmp/snmpd.conf
Expand All @@ -8,7 +14,7 @@

- name: restart service

Check warning on line 15 in handlers/main.yml

View workflow job for this annotation

GitHub Actions / Lint

name[casing]

All names should start with an uppercase letter.
ansible.builtin.service:
name: snmpd
name: "{{ snmpd_service_name }}"
state: restarted
listen: restart snmpd
when: service_default_state | default('started') == 'started'
2 changes: 1 addition & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@

- name: start and enable service
ansible.builtin.service:
name: snmpd
name: "{{ snmpd_service_name }}"
state: "{{ service_default_state | default('started') }}"
enabled: "{{ service_default_enabled | default(true) | bool }}"
tags:
Expand Down
2 changes: 2 additions & 0 deletions vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ snmpd_dependencies:
- snmpd
- snmp
- snmp-mibs-downloader

snmpd_service_name: snmpd

0 comments on commit 5ad1da3

Please sign in to comment.