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.smart, tags: "smart" }
- { role: mgrote.postfix, tags: "postfix" } - { role: mgrote.postfix, tags: "postfix" }
- { role: mgrote.ecc-rasdaemon, - { role: mgrote.ecc-rasdaemon,
tags: "ecc", tags: "ecc" }
when: "'pve2.grote.lan' in inventory_hostname" }
- { role: mgrote.cv4pve-autosnap, - { role: mgrote.cv4pve-autosnap,
tags: "cv4pve", tags: "cv4pve",
when: "'pve2.grote.lan' in inventory_hostname" } 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 become: yes
shell: '/usr/sbin/ras-mc-ctl --guess-labels >> /var/log/rasdaemon.log' 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 become: true
ansible.builtin.package: ansible.builtin.package:
name: name:
- rasdaemon - rasdaemon
- logrotate - logrotate
state: present state: present
notify: labels notify: guess-labels
- name: Enable rasdaemon service - name: enable rasdaemon service
become: true become: true
ansible.builtin.service: ansible.builtin.service:
name: rasdaemon name: rasdaemon
enabled: true enabled: true
- name: Start rasdaemon service - name: start rasdaemon service
become: true become: true
ansible.builtin.service: ansible.builtin.service:
name: rasdaemon name: rasdaemon
state: started state: started
- name: Create rasdaemon log - name: create rasdaemon log
become: true become: true
ansible.builtin.file: ansible.builtin.file:
path: /var/log/rasdaemon.log path: /var/log/rasdaemon.log
state: touch state: touch
access_time: preserve access_time: preserve
modification_time: preserve modification_time: preserve
owner: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
- name: copy logrotate config - name: copy logrotate config
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: logrotate_rasdaemon src: logrotate_rasdaemon
dest: /etc/logrotate.d/rasdaemon dest: /etc/logrotate.d/rasdaemon
owner: root owner: "{{ rasdaemon_user }}"
group: root group: "{{ rasdaemon_user_group }}"
mode: 0644 mode: 0644
- name: rasdaemon-cron kopieren - name: copy rasdaemon-cron.sh
become: yes become: yes
ansible.builtin.template: ansible.builtin.template:
src: rasdaemon-cron.sh src: rasdaemon-cron.sh
dest: "/usr/local/bin/rasdaemon-cron.sh" dest: "/usr/local/bin/rasdaemon-cron.sh"
mode: a+x mode: a+x
owner: "{{ rasdaemon_user }}"
group: "{{ rasdaemon_user_group }}"
- name: create cronjob - name: create cronjob
become: yes become: yes
@ -52,3 +59,4 @@
job: /usr/local/bin/rasdaemon-cron.sh job: /usr/local/bin/rasdaemon-cron.sh
minute: "5" minute: "5"
hour: "4,8,12,16,20,0" 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 {{ sanoid_user }} ALL=(ALL) NOPASSWD:ALL
validate: '/usr/sbin/visudo -cf %s' validate: '/usr/sbin/visudo -cf %s'
backup: yes backup: yes
marker_begin: sanoid-sudoers
marker_end: sanoid-sudoers
when: when:
- sanoid_user_group is defined - sanoid_user_group is defined
- sanoid_user is defined - sanoid_user is defined