Skip to content

Role is not idempotent in case of rule's loading failure #64

Description

@w4hf

If a run update the rules and the Load audit rules handler fails, the next run will run successfully while it should fail to keep idempotency.

To reproduce :

  1. Create a non working new rule, for example monitor a file in a dir that do not exist :
auditd_rules:
  - path: /etc/idontexist/metoo
    action: always
    filter: exit
    permission:
      - write
      - attribute_change
    keyname: testing
  1. Run the role for the first time --> it will fail when running the handler Load audit rules (augenrules --load) with the following error
RUNNING HANDLER [auditd : Load audit rules] ****************************************************************************************************************************************************************************************************************************
[ERROR]: Task failed: Module failed: The command exited with a non-zero return code.
Origin: /home/w4hf/projects/ANSIBLE/EDA/kafka/roles/auditd/handlers/main.yml:9:3

7   notify: Load audit rules
8
9 - name: Load audit rules
    ^ column 3

fatal: [dev.home]: FAILED! => {"changed": true, "changed_when_result": true, "cmd": ["augenrules", "--load"],
 "delta": "0:00:00.010973", "end": "2026-09-02 19:02:15.277148", 
"msg": "The command exited with a non-zero return code.", 
"rc": 1, "start": "2026-09-02 19:02:15.266175", 
"stderr": "Error sending add rule data request (No such file or directory)\nThere was an error in line 8 of /etc/audit/audit.rules",
"stderr_lines": [
  "Error sending add rule data request (No such file or directory)",
  "There was an error in line 8 of /etc/audit/audit.rules"],
"stdout": "/usr/sbin/augenrules: No change\nNo rules\nenabled 1\nfailure 1 ....
  1. Run again without changing anything --> the role succeed when it should fail, because the handlers are not triggered since there is no change therefore the augenrules --load doesn't execute.

One solution would be : if the role detect that there is no changes to custom rules ("Deploy custom audit rules" task is not changed ), then the role must run the augenrules --check command, if this command return No change then the role must run the augenrules --load command to guarantee its idempotency and fail if the declared rules are not correct.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions