-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem_initial_setup.yml
181 lines (153 loc) · 5.06 KB
/
system_initial_setup.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
---
- name: Initial setup from vanilla raspbian image
hosts: raspberrypi
remote_user: pi
become: yes
become_user: root
vars:
raspberry_local_autologin: true
raspberry_replace_sshd: true
raspberry_headless: true
raspberry_hostname: raspberrypi
raspberry_root_password: 7DxvI5PmjRsJW60da2EgjbdR
raspberry_user_password: bnjKfFvSqoje3Mv4YRgv3gxI
raspberry_ssh_keys:
- 'ssh-rsa blablablabla foo@bar'
raspberry_packages_install:
- tmux
- mtr-tiny
- tcpdump
- iptraf
- vim
- sysstat
- iotop
- htop
- lsof
- dosfstools
- w3m
- ifenslave
- inetutils-syslogd
- nmap
- tshark
- nethogs
- bridge-utils
- iw
raspberry_packages_deinstall:
- aspell
- desktop-base
- gnome-icon-theme
- gnome-themes-standard
- hunspell-en-us
- libaspell15
- libgtk2.0-common
- libgtk-3-common
- libqtgui4
- libwebkitgtk-1.0-0
- libwebkitgtk-3.0-0
- lxde
- lxde-icon-theme
- lxsession
- lxtask
- lxterminal
- omxplayer
- python-pygame
- scratch
- squeak-vm
- xserver-common
- zenity
- dillo
- libqt4-network
- libqtdbus4
- libqt4-xml
- libqtcore4
- cups-bsd
- cups-client
- cups-common
- ntp
- wolfram-engine
- rsyslog
raspberry_services_deactivate:
- triggerhappy
ansible_ssh_pass: raspberry
tasks:
- name: Set hostname
hostname: name="{{ raspberry_hostname }}"
- name: expand root filesystem
command: raspi-config --expand-rootfs
- name: bash prompt
copy: src=files/bash.prompt dest=/etc/bash.prompt owner=root group=root mode='0644'
- name: .bashrc file
copy: src=files/.bashrc dest=/root/.bashrc owner={{ item }} group={{ item }} mode='0644'
with_items:
- root
- pi
- name: Add wheel group
group: name=wheel state=present system=yes
- name: Add SSH key
authorized_key: user={{ item[0] }} key="{{ item[1] }}" state=present
with_nested:
- [ 'pi', 'root' ]
- raspberry_ssh_keys
- name: Set up pi user
user: name=pi state=present password={{ raspberry_user_password | password_hash('sha512') }} update_password=always groups=wheel,sudo append=yes
- name: Set up root user
user: name=root state=present password={{ raspberry_root_password | password_hash('sha512') }} update_password=always groups=wheel append=yes
- name: Passwordless su for pi user
lineinfile: state=present dest=/etc/pam.d/su regexp="^.*auth\s+sufficient pam_wheel.so trust" line="auth sufficient pam_wheel.so trust"
- name: disable serial console
command: systemctl {{ item }} [email protected]
with_items:
- stop
- disable
- name: Local autologin on tty1
lineinfile: state=present dest=/etc/systemd/system/getty.target.wants/[email protected] regexp="^ExecStart=.+$" line="ExecStart=-/sbin/agetty --noclear --autologin root %I $TERM"
when: raspberry_local_autologin
- name: Install any updates (safe-upgrade)
apt: upgrade=safe
register: packageupdate
- name: Packages to remove
apt: pkg={{ item }} state=absent purge=yes
with_items: raspberry_packages_deinstall
- name: Packages to install
apt: pkg={{ item }} state=latest
with_items: raspberry_packages_install
- name: Package cleanup
command: "{{ item }}"
with_items:
- apt-get -y autoclean
- apt-get -y autoremove
- name: services to stop
command: service {{ item }} stop
with_items: raspberry_services_deactivate
- name: services to deactivate
command: update-rc.d {{ item }} remove
with_items: raspberry_services_deactivate
- name: turn off video output
copy: src=files/rc.local dest=/etc/rc.local owner=root group=root mode='0755'
when: raspberry_headless
- name: zram init file
copy: src=files/zram dest=/etc/init.d/zram owner=root group=root mode='0755'
- name: Activate zram
service: enabled=yes name=zram state=started
- name: Change tmp directories to tmpfs
lineinfile: dest=/etc/fstab regexp="^tmpfs {{ item }}" line="tmpfs {{ item }} tmpfs rw,nosuid,nodev,noexec,noatime,mode=1777 0 0"
with_items:
- /tmp
- /var/tmp
- name: Install dropbear
apt: pkg=dropbear state=latest
when: raspberry_replace_sshd
- name: Activate dropbear
lineinfile: state=present dest=/etc/default/dropbear regexp="^NO_START=.+$" line="NO_START=0"
when: raspberry_replace_sshd
- name: Stop openssh
service: name=ssh state=stopped
when: raspberry_replace_sshd
- name: Start dropbear
service: name=dropbear state=started
when: raspberry_replace_sshd
- name: Remove openssh
apt: pkg=openssh-server state=absent
when: raspberry_replace_sshd
- name: Reboot device
command: shutdown -r now