ansible: user für rasdaemon erstellt (#270)

Co-authored-by: Michael Grote <michael.grote@posteo.de>
Reviewed-on: mg/ansible#270
Co-authored-by: mg <michael.grote@posteo.de>
Co-committed-by: mg <michael.grote@posteo.de>
This commit is contained in:
Michael Grote 2021-12-12 16:07:35 +01:00
parent 53b003628b
commit 347d80a8a4
6 changed files with 57 additions and 11 deletions

View file

@ -13,8 +13,7 @@
- { role: mgrote.smart, tags: "smart" }
- { role: mgrote.postfix, tags: "postfix" }
- { role: mgrote.ecc-rasdaemon,
tags: "ecc",
when: "'pve2.grote.lan' in inventory_hostname" }
tags: "ecc" }
- { role: mgrote.cv4pve-autosnap,
tags: "cv4pve",
when: "'pve2.grote.lan' in inventory_hostname" }

View file

@ -0,0 +1,4 @@
---
### under which user the script is run
rasdaemon_user_group: "root"
rasdaemon_user: "rasdaemon"

View file

@ -1,4 +1,4 @@
---
- name: labels
- name: guess-labels
become: yes
shell: '/usr/sbin/ras-mc-ctl --guess-labels >> /var/log/rasdaemon.log'

View file

@ -1,48 +1,55 @@
---
- name: Install rasdaemon
- name: include user tasks
include_tasks: user.yml
- name: install rasdaemon
become: true
ansible.builtin.package:
name:
- rasdaemon
- logrotate
state: present
notify: labels
notify: guess-labels
- name: Enable rasdaemon service
- name: enable rasdaemon service
become: true
ansible.builtin.service:
name: rasdaemon
enabled: true
- name: Start rasdaemon service
- name: start rasdaemon service
become: true
ansible.builtin.service:
name: rasdaemon
state: started
- name: Create rasdaemon log
- name: create rasdaemon log
become: true
ansible.builtin.file:
path: /var/log/rasdaemon.log
state: touch
access_time: preserve
modification_time: preserve
owner: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
- name: copy logrotate config
become: yes
ansible.builtin.template:
src: logrotate_rasdaemon
dest: /etc/logrotate.d/rasdaemon
owner: root
group: root
owner: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
mode: 0644
- name: rasdaemon-cron kopieren
- name: copy rasdaemon-cron.sh
become: yes
ansible.builtin.template:
src: rasdaemon-cron.sh
dest: "/usr/local/bin/rasdaemon-cron.sh"
mode: a+x
owner: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
- name: create cronjob
become: yes
@ -52,3 +59,4 @@
job: /usr/local/bin/rasdaemon-cron.sh
minute: "5"
hour: "4,8,12,16,20,0"
user: "{{ rasdaemon_user }}"

View file

@ -0,0 +1,33 @@
---
- name: ensure group exists
become: true
ansible.builtin.group:
name: "{{ rasdaemon_user_group }}"
state: present
when:
- rasdaemon_user_group is defined
- name: ensure user exists
become: true
ansible.builtin.user:
name: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
shell: /usr/sbin/nologin
when:
- rasdaemon_user_group is defined
- rasdaemon_user is defined
- name: add user to sudoers
become: true
ansible.builtin.blockinfile:
path: /etc/sudoers
state: present
block: |
{{ rasdaemon_user }} ALL=(ALL) NOPASSWD:ALL
validate: '/usr/sbin/visudo -cf %s'
backup: yes
marker_begin: rasdaemon-sudoers
marker_end: rasdaemon-sudoers
when:
- rasdaemon_user_group is defined
- rasdaemon_user is defined

View file

@ -26,6 +26,8 @@
{{ sanoid_user }} ALL=(ALL) NOPASSWD:ALL
validate: '/usr/sbin/visudo -cf %s'
backup: yes
marker_begin: sanoid-sudoers
marker_end: sanoid-sudoers
when:
- sanoid_user_group is defined
- sanoid_user is defined