2022-04-16 20:55:19 +02:00
|
|
|
---
|
|
|
|
- name: "Add backup user"
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: backup
|
|
|
|
comment: Backup user
|
|
|
|
shell: /bin/bash
|
|
|
|
|
|
|
|
- name: "Dsiable service user"
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: service-user
|
|
|
|
state: present
|
|
|
|
password_lock: true
|
|
|
|
shell: "/sbin/nologin"
|
2022-04-16 21:00:08 +02:00
|
|
|
|
|
|
|
- name: Undefine AllowUsers
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2022-04-16 21:00:08 +02:00
|
|
|
state: absent
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
line: "AllowUsers tormakris ansible service-user"
|
|
|
|
|
|
|
|
- name: Check if AllowUsers is defined
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2022-04-16 21:00:08 +02:00
|
|
|
state: absent
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
regexp: "^AllowUsers"
|
|
|
|
check_mode: true
|
|
|
|
changed_when: false
|
|
|
|
register: checkallowusers
|
|
|
|
|
|
|
|
- name: Define AllowUsers if undefined
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.lineinfile:
|
2022-04-16 21:00:08 +02:00
|
|
|
state: present
|
|
|
|
path: /etc/ssh/sshd_config
|
|
|
|
line: "AllowUsers tormakris ansible backup"
|
|
|
|
when: checkallowusers.found == 0
|
2022-04-16 21:03:00 +02:00
|
|
|
|
|
|
|
- name: "Restart sshd"
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.service:
|
2022-04-16 21:03:00 +02:00
|
|
|
name: sshd
|
2022-04-16 21:05:42 +02:00
|
|
|
state: restarted
|
2022-04-16 21:17:11 +02:00
|
|
|
|
2022-04-16 21:20:11 +02:00
|
|
|
- name: Create .ssh directory of backup user
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.file:
|
2022-04-16 21:20:11 +02:00
|
|
|
path: /home/backup/.ssh
|
|
|
|
state: directory
|
|
|
|
|
2022-04-16 21:17:11 +02:00
|
|
|
- name: Copy authorized_keys
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.copy:
|
2022-04-16 21:17:11 +02:00
|
|
|
src: authorized_keys
|
|
|
|
dest: /home/backup/.ssh/authorized_keys
|
|
|
|
mode: 0600
|
|
|
|
owner: backup
|
|
|
|
group: backup
|
|
|
|
|
|
|
|
- name: Copy ssh config
|
2023-03-05 19:00:38 +01:00
|
|
|
ansible.builtin.copy:
|
2022-04-16 21:17:11 +02:00
|
|
|
src: ssh_config
|
|
|
|
dest: /home/backup/.ssh/config
|
|
|
|
mode: 0600
|
|
|
|
owner: backup
|
|
|
|
group: backup
|
2022-04-16 20:55:19 +02:00
|
|
|
...
|