Skip to content

Commit 084381b

Browse files
committed
lots more raspberry pi ansible improvements
1 parent bc1fe33 commit 084381b

11 files changed

+158
-53
lines changed

doc/non-ansible-configuration-notes.md

+2-7
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,16 @@ Set up SD card:
103103

104104
Set up running system, steps to execute in `raspi-config`:
105105

106-
* Expand Filesystem
107106
* Change User Password
108-
* Internationalisation Options - Change Locale to en_US.UTF8
109-
* Internationalisation Options - Change Keyboard Layout - Generic non-Intl, English (US)
110-
* Overclock Pi 1 B+ to Medium
111-
* Advanced - Hostname, replace `_` with `--`
112107
* Advanced - Enable SSH
113108

114109
Then, manually:
115110

116-
* Set up .ssh/authorized_keys as appropriate for running Ansible (Insert the `nodejs_build_test` key or the `nodejs_build_release` key as appropriate)
111+
* Set up ~pi/.ssh/authorized_keys as appropriate for running Ansible (Insert the `nodejs_build_test` key or the `nodejs_build_release` key as appropriate). Set ~pi/.ssh to mode 755 and ~pi/.ssh/authorized_keys to mode 644.
117112
* Ensure that it can boot on the network and local SSH configuration matches the host (reprovisioned hosts will need a replacement of your `known_hosts` entry for it)
118113
* Update <https://github.com/nodejs/build/blob/master/setup/ansible-inventory> to include any new hosts under `[iojs-raspbian]`
119114
* Update <https://github.com/nodejs/build/blob/master/ansible/inventory.yml> to reflect any host additions or changes (this is primarily for automatic .ssh/config setup purposes currently)
120-
* Run Ansible from <https://github.com/nodejs/build/tree/master/setup/raspberry-pi>
115+
* Run Ansible from <https://github.com/nodejs/build/tree/master/setup/raspberry-pi> with `ansible-playbook ansible-playbook.yaml -i ../ansible-inventory --limit <hostname>`
121116

122117

123118
[`ansible.intro_windows`]: http://docs.ansible.com/ansible/intro_windows.html

setup/ansible-tasks/ccache.yaml

+14-3
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,43 @@
55
- name: CCache | Check ccache --version
66
shell: ccache --version
77
ignore_errors: True
8-
register: ccache_version
8+
register: installed_version
9+
tags: ccache
910

1011
- name: CCache | Compare installed version matches
1112
set_fact:
12-
ccache_proceed: ccache_version.stdout.find('{{ version }}') == -1
13+
ccache_proceed: "{{ installed_version.stdout.find(version) == -1 }}"
14+
tags: ccache
1315

1416
- name: CCache | Download ccache-{{ version }}
1517
get_url: url=https://www.samba.org/ftp/ccache/ccache-{{ version }}.tar.gz dest=/tmp/
1618
register: new_archive
1719
when: ccache_proceed
20+
tags: ccache
1821

1922
- name: CCache | Extract ccache-{{ version }}
2023
unarchive: src=/tmp/ccache-{{ version }}.tar.gz dest=/tmp/ copy=no
2124
when: ccache_proceed and new_archive|changed
25+
tags: ccache
2226

2327
- name: CCache | Prepare for compilation by running configure
2428
shell: ./configure chdir=/tmp/ccache-{{ version }} >> /dev/null
2529
when: ccache_proceed
30+
tags: ccache
2631

2732
- name: CCache | Compile ccache
28-
shell: make chdir=/tmp/ccache-{{ version }} >> /dev/null
33+
shell: make -j{{ ansible_processor_vcpus }}
34+
args:
35+
chdir: /tmp/ccache-{{ version }}
2936
when: ccache_proceed
37+
tags: ccache
3038

3139
- name: CCache | Install generated binary
3240
command: install -c -m 755 ccache /usr/local/bin
3341
args:
3442
chdir: /tmp/ccache-{{ version }}
3543
when: ccache_proceed
44+
tags: ccache
3645

3746
- name: CCache | Create symlinks in /usr/local/bin/
3847
file: src=/usr/local/bin/ccache dest=/usr/local/bin/{{ item }} state=link
@@ -42,10 +51,12 @@
4251
- g++
4352
- c++
4453
when: ccache_proceed
54+
tags: ccache
4555

4656
- name: CCache | Cleanup
4757
file: path="{{ item }}" state=absent
4858
with_items:
4959
- /tmp/ccache-{{ version }}.tar.gz
5060
- /tmp/ccache-{{ version }}
5161
when: ccache_proceed
62+
tags: ccache

setup/ansible-tasks/git.yaml

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55
- name: Git | Check git --version
66
shell: git --version
77
ignore_errors: True
8-
register: git_version
8+
register: installed_version
9+
tags: git
10+
11+
- name: Git | Compare installed version matches
12+
set_fact:
13+
git_proceed: "{{ installed_version.stdout.find(version) == -1 }}"
14+
tags: git
915

1016
- name: Git | Install required packages for git compile
1117
apt: name={{ item }} update_cache=yes state=latest
@@ -15,41 +21,43 @@
1521
- gettext
1622
- libcurl4-openssl-dev
1723
- zlib1g-dev
18-
when: git_version.stdout.find('{{ version }}') == -1
24+
when: git_proceed
1925
tags: git
2026

2127
- name: Git | Download git-{{ version }}
2228
get_url: url=https://www.kernel.org/pub/software/scm/git/git-{{ version }}.tar.xz dest=/tmp/
2329
register: new_archive
24-
when: git_version.stdout.find('{{ version }}') == -1
30+
when: git_proceed
2531
tags: git
2632

2733
- name: Git | Extract git-{{ version }}
2834
unarchive: src=/tmp/git-{{ version }}.tar.xz dest=/tmp/ copy=no
29-
when: git_version.stdout.find('{{ version }}') == -1 and new_archive|changed
35+
when: git_proceed and new_archive|changed
3036
tags: git
3137

3238
- name: Git | Prepare for compilation by running configure
3339
shell: ./configure --prefix=/usr --with-gitconfig=/etc/gitconfig chdir=/tmp/git-{{ version }} >> /dev/null
34-
when: git_version.stdout.find('{{ version }}') == -1
40+
when: git_proceed
3541
tags: git
3642

3743
- name: Git | Compile git
38-
shell: make chdir=/tmp/git-{{ version }} >> /dev/null
39-
when: git_version.stdout.find('{{ version }}') == -1
44+
shell: make -j{{ ansible_processor_vcpus }}
45+
args:
46+
chdir: /tmp/git-{{ version }}
47+
when: git_proceed
4048
tags: git
4149

4250
- name: Git | Install generated binary
4351
command: make install
4452
args:
4553
chdir: /tmp/git-{{ version }}
46-
when: git_version.stdout.find('{{ version }}') == -1
54+
when: git_proceed
4755
tags: git
4856

4957
- name: Git | Cleanup
5058
file: path="{{ item }}" state=absent
5159
with_items:
5260
- /tmp/git-{{ version }}.tar.gz
5361
- /tmp/git-{{ version }}
54-
when: git_version.stdout.find('{{ version }}') == -1
62+
when: git_proceed
5563
tags: git

setup/ansible-tasks/monit.yaml

+21-9
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,34 @@
22
# Installs and configures monit for Debian based systems.
33
# @requires: monit_conf_file=../ansible-tasks/resources/monit-jenkins.conf
44

5-
- name: Monit | Install deb package
6-
apt: name=monit update_cache=yes state=latest
5+
- name: Monit | Install monit
6+
apt:
7+
name: monit
8+
update_cache: yes
9+
state: latest
710
tags: monit
811

912
- name: Monit | Set the cycle length to 15 seconds
10-
lineinfile: dest=/etc/monit/monitrc state=present regexp="^(\s*)set(\s+)daemon" line="set daemon 15"
13+
lineinfile:
14+
dest: /etc/monit/monitrc
15+
state: present
16+
regexp: "^(\\s*)set(\\s+)daemon"
17+
line: "set daemon 15"
1118
tags: monit
1219

1320
- name: Monit | Copy monit config
14-
copy: src={{ monit_conf_file }} dest=/etc/monit/conf.d/jenkins owner=root group=root mode=0644
15-
tags: monit
16-
17-
- name: Monit | Copy server user name to monit config
18-
replace: dest=/etc/monit/conf.d/jenkins regexp="\{\{server_user\}\}" replace="{{ server_user }}"
21+
template:
22+
src: "./resources/monit-jenkins.conf.j2"
23+
dest: "/etc/monit/conf.d/jenkins"
24+
owner: "root"
25+
group: "root"
26+
mode: 0644
27+
register: monit_config
1928
tags: monit
2029

2130
- name: Monit | Restart service
22-
service: name=monit state=restarted
31+
service:
32+
name: monit
33+
state: restarted
34+
when: monit_config.changed
2335
tags: monit

setup/ansible-tasks/resources/monit-jenkins.conf

-4
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
check process jenkins
2+
matching slave.jar
3+
start program = "/bin/su {{ server_user }} -c 'cd /home/{{ server_user }} && /home/{{ server_user }}/start.sh'"
4+
stop program = "/bin/su {{ server_user }} -c 'pkill -f slave.jar'"

setup/raspberry-pi/ansible-playbook.yaml

+88-14
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@
1010
- name: Init | Discover Pi type
1111
set_fact:
1212
pi_type: "{{ inventory_hostname | regex_replace('^.+_(pi[^-]+)-\\d+$', '\\1') }}"
13+
tags: vars
14+
15+
- name: Init | Discover worker type
16+
set_fact:
17+
worker_type: "{{ inventory_hostname | regex_replace('^(test|release)-.+$', '\\1') }}"
18+
tags: vars
19+
20+
- name: Init | Generate hostname
21+
set_fact:
22+
safe_hostname: "{{ inventory_hostname | regex_replace('_', '--') }}"
23+
tags: vars
1324

1425
- name: General | Setup APT proxy
1526
template:
@@ -28,6 +39,7 @@
2839
owner: "root"
2940
group: "root"
3041
mode: 0644
42+
when: pi_local is undefined
3143
tags: general
3244

3345
- name: General | APT update
@@ -56,6 +68,62 @@
5668
when: ssh_remove_dns.changed
5769
tags: init
5870

71+
- name: General | Setup keyboard config
72+
template:
73+
src: "./resources/keyboard-defaults.j2"
74+
dest: "/etc/default/keyboard"
75+
owner: "root"
76+
group: "root"
77+
mode: 0644
78+
register: keyboard_config
79+
tags: general
80+
81+
- name: General | Setup keyboard config
82+
shell: dpkg-reconfigure -f noninteractive keyboard-configuration && invoke-rc.d keyboard-setup start
83+
when: keyboard_config.changed
84+
tags: general
85+
86+
- name: General | Setup locale
87+
shell:
88+
cmd: |
89+
cat << EOF | debconf-set-selections
90+
locales locales/locales_to_be_generated multiselect en_US.UTF-8 UTF-8
91+
EOF
92+
rm /etc/locale.gen
93+
dpkg-reconfigure -f noninteractive locales
94+
update-locale LANG="en_US.UTF-8"
95+
cat << EOF | debconf-set-selections
96+
locales locales/default_environment_locale select en_US.UTF-8
97+
EOF
98+
tags: general
99+
100+
- name: General | Expand root disk
101+
shell:
102+
cmd: |
103+
ROOT_PART=$(readlink /dev/root)
104+
PART_NUM=${ROOT_PART#mmcblk0p}
105+
PART_START=$(parted /dev/mmcblk0 -ms unit s p | grep "^${PART_NUM}" | cut -f 2 -d:)
106+
fdisk /dev/mmcblk0 << EOF || true
107+
p
108+
d
109+
$PART_NUM
110+
n
111+
p
112+
$PART_NUM
113+
$PART_START
114+
115+
p
116+
w
117+
EOF
118+
tags: general
119+
120+
- name: General | Set hostname
121+
shell:
122+
cmd: |
123+
echo {{ safe_hostname }} > /etc/hostname
124+
sed -i "s/127.0.1.1.*{{ safe_hostname }}/127.0.1.1\t{{ safe_hostname }}/g" /etc/hosts
125+
tags: general
126+
59127
- name: General | Configure 1024M dphys-swapfile
60128
lineinfile:
61129
dest: /etc/dphys-swapfile
@@ -191,32 +259,38 @@
191259
mode: 0755
192260
tags: jenkins
193261

194-
- name: ccache | Install ccache
195-
import_tasks: ../ansible-tasks/ccache.yaml version=3.3.4
196-
tags: ccache
197-
198-
- name: git | Install git
199-
import_tasks: ../ansible-tasks/git.yaml version=2.15.0
200-
tags: git
201-
202-
- name: monit | Install monit
203-
import_tasks: ../ansible-tasks/monit.yaml monit_conf_file=../ansible-tasks/resources/monit-jenkins.conf
204-
tags: monit
205-
206262
- name: Tunnel | Copy start_tunnel.sh script
207-
when: pi_local is defined
208263
template:
209264
src: "./resources/start_tunnel.j2"
210265
dest: "/usr/local/sbin/start_tunnel.sh"
211266
owner: "{{ server_user }}"
212267
group: "{{ server_user }}"
213268
mode: 0755
269+
when: pi_local is defined
214270
tags: tunnel
215271

216272
- name: Tunnel | crontab entry
217-
when: pi_local is defined
218273
cron:
219274
name: 'start ssh tunnel on reboot'
220275
special_time: reboot
221276
job: "/usr/local/sbin/start_tunnel.sh"
277+
when: pi_local is defined
222278
tags: tunnel
279+
280+
- name: ccache | Install ccache
281+
import_tasks: ../ansible-tasks/ccache.yaml
282+
vars:
283+
version: 3.3.4
284+
tags: ccache
285+
286+
- name: git | Install git
287+
import_tasks: ../ansible-tasks/git.yaml
288+
vars:
289+
version: 2.15.0
290+
tags: git
291+
292+
- name: monit | Install monit
293+
import_tasks: ../ansible-tasks/monit.yaml
294+
vars:
295+
monit_conf_file: ../ansible-tasks/resources/monit-jenkins.conf.j2
296+
tags: monit

setup/raspberry-pi/resources/boot-config.pi1p.txt.j2

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
arm_freq=800
1+
arm_freq={{ '700' if worker_type == 'release' else '800' }}
22
dtparam=audio=on
33
core_freq=250
44
sdram_freq=400

setup/raspberry-pi/resources/do_mount.j2

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
XKBMODEL="pc104"
2+
XKBLAYOUT="us"
3+
XKBVARIANT=""
4+
XKBOPTIONS=""
5+
BACKSPACE="guess"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
#!/bin/sh
22

3-
autossh -f -M 0 -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" [email protected] -L {{ ci_port }}:ci-release.nodejs.org:{{ ci_port }} -N
3+
autossh -f -M 0 \
4+
-o "ServerAliveInterval 30" \
5+
-o "ServerAliveCountMax 3" \
6+
7+
-L {{ ci_port }}:ci-release.nodejs.org:{{ ci_port }} \
8+
-N

0 commit comments

Comments
 (0)