Skip to content

Commit c4aae18

Browse files
authored
fix: detect rfc5424 changes on existing syslog destinations (#436)
rfc5424 was in FIELDS_ALL but not FIELDS_CHANGE. update() (base module) only compares FIELDS_CHANGE to detect drift, so flipping rfc5424 on an existing destination yielded changed=False and no API POST — the setting silently no-oped and had to be applied by hand in the GUI. The POST payload builder iterates FIELDS_ALL and already included rfc5424, so the value applied once some other change triggered an update; the gap was purely change detection. Add rfc5424 to FIELDS_CHANGE (and drop it from the FIELDS_ALL literal, since FIELDS_ALL extends FIELDS_CHANGE) so a standalone rfc5424 change is detected. The OPNsense Syslog model stores rfc5424 as a BooleanField returned by the API, so detection reads the real current value and stays idempotent; drop the stale "not getting current value from response" comment that claimed otherwise. Add a change-detection/idempotency regression to tests/syslog.yml. Assisted-By: Claude <noreply@anthropic.com>
1 parent 8b8da47 commit c4aae18

3 files changed

Lines changed: 36 additions & 3 deletions

File tree

plugins/module_utils/main/syslog.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ class Syslog(BaseModule):
2323
API_CONT_REL = 'service'
2424
FIELDS_CHANGE = [
2525
'target', 'transport', 'facility', 'program', 'level', 'certificate',
26-
'port', 'description',
26+
'port', 'description', 'rfc5424',
2727
]
28-
FIELDS_ALL = ['rfc5424', 'enabled']
28+
FIELDS_ALL = ['enabled']
2929
FIELDS_ALL.extend(FIELDS_CHANGE)
3030
FIELDS_TRANSLATE = {
3131
'target': 'hostname',

plugins/modules/syslog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def run_module():
5454
],
5555
),
5656
certificate=dict(type='str', required=False, aliases=['cert']),
57-
rfc5424=dict(type='bool', required=False, default=False), # not getting current value from response
57+
rfc5424=dict(type='bool', required=False, default=False),
5858
description=dict(type='str', required=False, aliases=['desc']),
5959
match_fields=dict(
6060
type='list', required=False, elements='str',

tests/syslog.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,39 @@
107107
not opn8.changed
108108
when: not ansible_check_mode
109109

110+
- name: Enabling rfc5424 on 1
111+
oxlorg.opnsense.syslog:
112+
description: 'ANSIBLE_TEST_1'
113+
target: '192.168.0.1'
114+
rfc5424: true
115+
register: opn12
116+
failed_when: >
117+
opn12.failed or
118+
not opn12.changed
119+
when: not ansible_check_mode
120+
121+
- name: Enabling rfc5424 on 1 - nothing changed
122+
oxlorg.opnsense.syslog:
123+
description: 'ANSIBLE_TEST_1'
124+
target: '192.168.0.1'
125+
rfc5424: true
126+
register: opn13
127+
failed_when: >
128+
opn13.failed or
129+
opn13.changed
130+
when: not ansible_check_mode
131+
132+
- name: Disabling rfc5424 on 1
133+
oxlorg.opnsense.syslog:
134+
description: 'ANSIBLE_TEST_1'
135+
target: '192.168.0.1'
136+
rfc5424: false
137+
register: opn14
138+
failed_when: >
139+
opn14.failed or
140+
not opn14.changed
141+
when: not ansible_check_mode
142+
110143
- name: Listing
111144
oxlorg.opnsense.list:
112145
register: opn1

0 commit comments

Comments
 (0)