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

feat: Allow setup aide inside of cron job #7

Merged
merged 4 commits into from
Jan 7, 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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,34 @@ Default: `false`

Type: `bool`

### aide_cron_check

If set to `true`, configures periodic cron check for aide
If set to `false`, removes the periodic cron check

Default: `null`

Type: `bool`

### aide_cron_interval

Set check interval for cron

``` yaml
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * *
```

Default: `0 12 * * *`

Type: `string`

## Example Playbook

Including an example of how to use your role (for instance, with variables
Expand Down
14 changes: 14 additions & 0 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,17 @@ aide_check: false

# Enable database update phase
aide_update: false

# Enable periodic check
aide_cron_check: null

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * *
# Set cron check interval
aide_cron_interval: "0 12 * * *"
20 changes: 19 additions & 1 deletion tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
when: aide_db_template is not none

# - name: Print Header
# ansible.builtin.shell: head /etc/aide.conf || true
# ansible.builtin.command: head /etc/aide.conf || true

- name: Initialize AIDE database
when: aide_init | bool
Expand Down Expand Up @@ -104,3 +104,21 @@
ansible.builtin.file:
path: "{{ __aide_db_new_name }}"
state: absent

- name: Update aide check cron configuration if necessary
ansible.builtin.lineinfile:
path: /etc/crontab
regexp: "^.* root /usr/sbin/aide --check"
line: "{{ aide_cron_interval }} root /usr/sbin/aide --check"
when:
- aide_cron_check is not none
- aide_cron_check | bool

- name: Remove aide check cron configuration if necessary
ansible.builtin.lineinfile:
path: /etc/crontab
state: absent
regexp: "^.* root /usr/sbin/aide --check"
when:
- aide_cron_check is not none
- not aide_cron_check | bool
47 changes: 47 additions & 0 deletions tests/tests_check_cron.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-License-Identifier: MIT
---
- name: Ensure that the cron is set up
hosts: all
gather_facts: false
roles:
- role: linux-system-roles.aide
vars:
aide_init: true
aide_cron_check: true
aide_cron_interval: "0 12 * * *"
tasks:
# - name: Print crontab 1
# ansible.builtin.command: cat /etc/crontab

- name: Check file content
ansible.builtin.lineinfile:
path: /etc/crontab
regexp: "^.* root /usr/sbin/aide --check"
line: "0 12 * * * root /usr/sbin/aide --check"
state: present
register: result
failed_when: result.changed
vars:
__fingerprint: system_role:aide

- name: Ensure that the cron is not set up
hosts: all
gather_facts: false
roles:
- role: linux-system-roles.aide
vars:
aide_cron_check: false
tasks:
# - name: Print crontab 2
# ansible.builtin.command: cat /etc/crontab

- name: Check file content
ansible.builtin.lineinfile:
path: /etc/crontab
regexp: "^.* root /usr/sbin/aide --check"
line: "0 12 * * * root /usr/sbin/aide --check"
state: present
register: result
failed_when: not result.changed
vars:
__fingerprint: system_role:aide
radosroka marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion vars/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

# Examples of non-distribution specific (generic) internal variables:
__aide_config: aide.conf
__aide_packages: ['aide']
__aide_packages: ["aide", "crontabs"]
__aide_services: []
__aide_db_name: /var/lib/aide/aide.db.gz
__aide_db_new_name: /var/lib/aide/aide.db.new.gz
Expand Down
Loading