-
Notifications
You must be signed in to change notification settings - Fork 3
/
site.yml
107 lines (107 loc) · 2.98 KB
/
site.yml
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
---
- hosts: all
tasks:
- name: Set local timezone
file:
src: /usr/share/zoneinfo/America/New_York
path: /etc/localtime
state: link
tags:
- timezone
- name: Setup locales
block:
- name: Configure locale.gen for US-only
lineinfile:
dest: /etc/locale.gen
regexp: '{{ item.regex }}'
line: '{{ item.line }}'
loop:
- {regex: 'en_GB.UTF-8 UTF-8', line: '# en_GB.UTF-8 UTF-8'}
- {regex: 'en_US.UTF-8 UTF-8', line: en_US.UTF-8 UTF-8}
- name: Generate locales
command: locale-gen
- name: Set locale
command: update-locale LANG=en_US.UTF-8
tags:
- locales
- name: Setup keyboard
lineinfile:
dest: /etc/default/keyboard
regexp: 'XKBLAYOUT=gb'
line: 'XKBLAYOUT=us'
tags:
- keyboard
- name: Set hostname
copy:
content: '{{ inventory_hostname }}'
dest: /etc/hostname
tags:
- hostname
- name: Set up sudo
block:
- name: Create wheel group
group:
name: wheel
- name: Give passwordless sudo access to wheel group
copy:
content: '%wheel ALL=(ALL) NOPASSWD: ALL'
dest: /etc/sudoers.d/wheel
validate: /usr/sbin/visudo --check --file=%s
tags:
- sudo
- name: Enable ssh
service:
name: ssh
enabled: yes
tags:
- ssh
- name: Setup user account
block:
- name: Create new user account
user:
name: '{{ user_name }}'
password: '{{ user_password }}'
groups: wheel
append: yes
- name: Create user's ssh directory
file:
path: /home/{{ user_name }}/.ssh
mode: 0700
owner: '{{ user_name }}'
group: '{{ user_name }}'
state: directory
- name: Copy over ssh key from current Ansible controller as an authorized key
copy:
src: '{{ lookup("env", "HOME") }}/.ssh/id_ed25519.pub'
dest: /home/{{ user_name }}/.ssh/authorized_keys
mode: 0600
owner: '{{ user_name }}'
group: '{{ user_name }}'
tags:
- user_account
- name: Tasks done as the new user
block:
- name: Delete pi user
block:
- name: Delete pi user account
user:
name: pi
force: yes
state: absent
- name: Remove passwordless sudo access for pi account
file:
path: /etc/sudoers.d/010_pi-nopasswd
state: absent
tags:
- delete_pi
- name: Reboot
reboot:
connect_timeout: 1
reboot_timeout: 1
failed_when: false
tags:
- reboot
vars:
ansible_user: '{{ user_name }}'
tags:
- new_user