Skip to content

Commit 1be421d

Browse files
author
P4T12ICK
committed
Idempotence
1 parent 11cd8af commit 1be421d

3 files changed

Lines changed: 22 additions & 17 deletions

File tree

tasks/install_auditd.yml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
owner: splunkfwd
6464
group: splunkfwd
6565
mode: '0755'
66-
recurse: yes
6766
with_items:
6867
- /opt/splunkforwarder/etc/apps/auditd_app/local/
6968

@@ -74,5 +73,4 @@
7473
dest: /opt/splunkforwarder/etc/apps/auditd_app/local/inputs.conf
7574
owner: splunkfwd
7675
group: splunkfwd
77-
mode: '0644'
78-
force: yes
76+
mode: '0644'

tasks/install_osquery_linux.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@
1010
state: present
1111
update_cache: true
1212

13-
- name: drop the osquery_install.sh script /tmp
14-
become: true
15-
copy:
16-
src: osquery_install.sh
17-
dest: /tmp/osquery_install.sh
18-
mode: '0755'
19-
2013
- name: check if osquery service exist
2114
stat: path=/etc/init.d/osqueryd
2215
register: service_status
@@ -34,6 +27,14 @@
3427
state: stopped
3528
when: service_status.stat.exists
3629

30+
- name: drop the osquery_install.sh script /tmp
31+
become: true
32+
copy:
33+
src: osquery_install.sh
34+
dest: /tmp/osquery_install.sh
35+
mode: '0755'
36+
when: not osquery_installed.stat.exists | default(false)
37+
3738
- name: run osquery_install.sh
3839
become: true
3940
command: sh /tmp/osquery_install.sh
@@ -44,6 +45,7 @@
4445
file:
4546
path: /tmp/osquery_install.sh
4647
state: absent
48+
when: not osquery_installed.stat.exists | default(false)
4749

4850
- name: copy template.osquery.conf
4951
become: true
@@ -97,7 +99,6 @@
9799
owner: splunkfwd
98100
group: splunkfwd
99101
mode: '0755'
100-
recurse: yes
101102
with_items:
102103
- /opt/splunkforwarder/etc/apps/osquery_app/local/
103104

@@ -108,5 +109,4 @@
108109
dest: /opt/splunkforwarder/etc/apps/osquery_app/local/inputs.conf
109110
owner: splunkfwd
110111
group: splunkfwd
111-
mode: '0644'
112-
force: yes
112+
mode: '0644'

tasks/install_sysmon_linux.yml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@
4343
stat:
4444
path: /etc/sysmon/sysmon.xml
4545
register: sysmon_configured
46+
changed_when: false
47+
48+
- name: Check if sysmon service exists and is active
49+
become: true
50+
command: systemctl is-active sysmon.service
51+
register: sysmon_service_check
52+
changed_when: false
53+
failed_when: false
4654

4755
- name: launch with config
4856
become: true
4957
ansible.builtin.shell: sysmon -accepteula -i /tmp/SysMonLinux-CatchAll.xml
50-
when: not sysmon_configured.stat.exists | default(false)
58+
when: (not sysmon_configured.stat.exists | default(false)) and (sysmon_service_check.rc != 0 | default(true))
59+
changed_when: false
5160

5261
- name: install powershell
5362
become: true
@@ -64,7 +73,6 @@
6473
owner: splunkfwd
6574
group: splunkfwd
6675
mode: '0755'
67-
recurse: yes
6876
with_items:
6977
- /opt/splunkforwarder/etc/apps/sysmon_app/local/
7078

@@ -75,5 +83,4 @@
7583
dest: /opt/splunkforwarder/etc/apps/sysmon_app/local/inputs.conf
7684
owner: splunkfwd
7785
group: splunkfwd
78-
mode: '0644'
79-
force: yes
86+
mode: '0644'

0 commit comments

Comments
 (0)