-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathinitializeService.yml
More file actions
87 lines (75 loc) · 2.06 KB
/
initializeService.yml
File metadata and controls
87 lines (75 loc) · 2.06 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# Run this playbook to initialise the service machines
#
# It disables root login, creates admin users, and puts their ssh keys to the machines.
# You can only run this *once*, because afterwards the root user can't be used to login.
#
# In order to contact a droplet directly as root, you must also disable the SSH proxy
# for a host in your .ssh/config file, like:
#
# #Host service3-ams.internal.php.net
# # ProxyCommand none
#
# And also comment out the [ssh_connection] section in ansible.cfg (see the
# comment there)
# Example run:
# ansible-playbook initializeSerice.yml --limit analytics --extra-vars "@etc/admins.yml"
- hosts:
- rsync
- service
remote_user: root
tasks:
- name: Install rsync
apt:
name:
- rsync
state: present
update_cache: yes
- name: Create local directory
file:
state: directory
dest: /local
mode: "755"
- name: Create local systems directory
file:
state: directory
dest: /local/systems
mode: "755"
# Install Restic for all services as backup tool https://restic.net/
- name: Install Restic
package:
name: restic
state: present
update_cache: yes
# Add admin user and pubkey everywhere
- name: Create a linux user and add it to sudo group
user:
name: "{{ item.name }}"
create_home: yes
state: present
groups: sudo
append: yes
shell: /bin/bash
loop: "{{ admins }}"
# Allow members of group sudo to execute any command without specifying their password
- name: Configure sudoers
copy:
dest: /etc/sudoers.d/20-sudo-password
content: "%sudo ALL=(ALL) NOPASSWD: ALL"
- name: Copy admin's ssh-keys
loop: "{{ admins }}"
include_role:
name: add_ssh_key
vars:
username: "{{ item.name }}"
pubkeys: "{{ item.pubkeys }}"
- name: Disable root login
lineinfile:
path: /etc/ssh/sshd_config
regexp: ^PermitRootLogin
line: PermitRootLogin no
notify: restart ssh
handlers:
- name: restart ssh
service:
name: ssh
state: restarted