Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
---
- hosts: "{{ host_list }}"
become: yes
become_method: sudo
remote_user: "{{ my_user }}"
tasks:
- name: SUDO | Group sudo presence
ansible.builtin.group:
name: sudo
state: present
- name: SUDO | Group wheel absence
ansible.builtin.group:
name: wheel
state: absent
- name: SUDO | User presence (with groups)
ansible.builtin.user:
name: "{{ my_user }}"
state: present
groups: sudo
append: true
- name: SUDO | Reset ansible connection to apply group update
meta: reset_connection
- name: "SSH | Local public key is present for {{ my_user }}"
ansible.builtin.authorized_key:
comment: "Managed by Ansible from GitLab @free_zed"
key: https://gitlab.com/free_zed.keys
state: present
user: "{{ my_user }}"
- name: SSH | Disallow SSH password authentication for root
copy:
src: sshd_config
dest: /etc/ssh/sshd_config
- name: "SSH | Local public key is present for root"
ansible.builtin.authorized_key:
comment: "Managed by Ansible from GitLab @free_zed"
key: https://gitlab.com/free_zed.keys
state: present
user: root
- name: SSH | Remove no password directive
ansible.builtin.lineinfile:
path: /etc/sudoers
state: absent
regexp: 'NOPASSWD'
validate: '/usr/sbin/visudo -cf %s'