Skip to content

Instantly share code, notes, and snippets.

@dapi
Created August 17, 2021 09:26
Show Gist options
  • Save dapi/508ad6b45168fb8f607a7997784535e2 to your computer and use it in GitHub Desktop.
Save dapi/508ad6b45168fb8f607a7997784535e2 to your computer and use it in GitHub Desktop.
- hosts: user_systemd
tasks:
- name: Create users systemd subdirectories
become: yes
become_user: "{{ app_user }}"
file:
path: "/home/{{ app_user }}/.config/systemd/user"
state: directory
mode: 0775
- name: Enable linger for app_user
command: "loginctl enable-linger {{app_user}}"
- name: Add systemd services
template:
src: "{{ item.template }}"
dest: "/etc/systemd/system/{{ item.name }}"
force: true
owner: root
group: root
mode: 0644
when: item.state|default('present') != 'absent'
with_items: "{{ systemd_services }}"
notify:
- systemd daemon reload
- name: Comment DNS section
replace:
path: /etc/systemd/resolved.conf
regexp: '^(DNS=.*)'
replace: '#\1'
notify:
- systemd daemon reload
- name: Uncommenting ForwardToSyslog
replace:
path: /etc/systemd/journald.conf
regexp: '^#(ForwardToSyslog.*)'
replace: '\1'
notify:
- systemd daemon reload
- name: Change SystemMaxUse to 100mb
lineinfile:
path: /etc/systemd/journald.conf
regexp: '^#(SystemMaxUse*)'
line: 'SystemMaxUse=100M'
backrefs: yes
- name: Restart systemd-resolved
systemd:
state: restarted
name: systemd-resolved
handlers:
- name: systemd daemon reload
command: systemctl daemon-reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment