Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Commit 9ce58e8

Browse files
committed
Merge branch 'release/0.4.0'
2 parents 415cb14 + b45a599 commit 9ce58e8

File tree

37 files changed

+263
-88
lines changed

37 files changed

+263
-88
lines changed

.gitignore

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
11
.vagrant
2-
playbook.retry
3-
4-
hosts
5-
variables.yml
2+
/*.yml

README.md

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# ansible-rpi 0.3.1
1+
# ansible-rpi 0.4.0
22

33
## Purpose
44

@@ -24,6 +24,7 @@ Tested on a Rpi 3 B+ and a Rpi 1 B.
2424
- Optionnal custom SSH banner
2525
- Optionnal Wifi config
2626
- Optionnal Mosh support
27+
- Optionnal unsudo of the pi user
2728
- `download_server`: Turn the Rpi in a download server for ddl and torrents
2829
- Aria2 daemon
2930
- RPC interface for remote monitoring with optionnal SSL encryption
@@ -33,21 +34,26 @@ Tested on a Rpi 3 B+ and a Rpi 1 B.
3334
- Dynamic sources creation (*may be linked to previously configured network folders*)
3435
- Buffer handling optimized for a Raspberry
3536
- Optionnal `kodi` user with `kodi-standalone` and a minimal Openbox setup
37+
- `rpi_docker`: Setup and enable control of a distant Raspberry Pi Docker host via Ansible
38+
- [HypriotOS](https://blog.hypriot.com/) oriented setup
39+
- Docker containers and deamon are behind the firewall by default (*see Docker Support for more infos*)
40+
- Ansible tools are setup (*allowing you to use docker_container, docker_image Ansible modules…*)
3641

3742
### Incoming
3843

39-
- `swarm_node`: Setup a Rpi as a Docker Machine and join a Docker Swarm
44+
- Segmentation into roles
4045

4146
## Setup
4247

4348
### With examples
4449

4550
```
4651
# First
47-
cp hosts.inc hosts
52+
cp hosts.inc /etc/ansible/hosts
4853
4954
# Then
50-
cp variables.yml.inc host_vars/my-host.yml
55+
cp playbook.yml.inc playbook.yml
56+
cp variables.yml.inc /etc/ansible/host_vars/my-host.yml
5157
```
5258

5359
### Usage
@@ -66,6 +72,9 @@ Then the first time run:
6672
ansible-playbook playbook.yml -u pi --ask-pass
6773
```
6874

75+
**You can also store user name in inventory file and user's pass in your Ansible
76+
vault.**
77+
6978
### Dev with Vagrant
7079

7180
First run:
@@ -86,6 +95,9 @@ ansible all -m ping -u neo
8695
ansible-playbook playbook.yml -u neo --ask-become-pass
8796
```
8897

98+
**You can also store user name in inventory file and user's pass in your Ansible
99+
vault.**
100+
89101
## User password generation
90102

91103
`password_hash` is a useful Jinja filter but uses 656000 rounds for SHA512 hashing.
@@ -102,3 +114,41 @@ python -c "from passlib.hash import sha512_crypt; import getpass; print sha512_c
102114

103115
[1](https://github.com/ansible/ansible/issues/15326)
104116
[2](https://docs.ansible.com/ansible/faq.html#how-do-i-generate-crypted-passwords-for-the-user-module)
117+
118+
## Docker Support
119+
120+
In order to ease Docker handling on Rpi, I recommend the
121+
[HypriotOS image](http://blog.hypriot.com/downloads/).
122+
123+
### Current state
124+
125+
The `rpi_docker` role is tested with it, but may work with other setups.
126+
127+
Modify the following vars in order to adapt to your device:
128+
129+
```yml
130+
rd_limit_nofile: 1048576
131+
rd_limit_nproc: 1048576
132+
rd_limit_core: infinity
133+
```
134+
135+
### Security
136+
137+
The `common` role will secure the HypriotOS Rpi in a way that by default:
138+
139+
- `docker-machine create` will **fail**
140+
(_default user must have a NOPASSD sudo, see [](https://docs.docker.com/machine/drivers/generic/#/sudo-privileges)_)
141+
- Docker daemon tcp port (_2376_) will be unreachable (_however you can enable it manually in allowed_ports var_) but is started by default
142+
- Docker unix socket is accessible
143+
144+
You may want to look to [this](https://github.com/DieterReuter/arm-docker-fixes/tree/master/001-fix-docker-machine-1.8.0-create-for-arm)
145+
for a manual `docker-machine` setup.
146+
147+
Docker-machine and Raspbian Docker support may come in a future release.
148+
149+
### Defaults
150+
151+
- `storage_driver` is `overlay`
152+
- The `tlsverify` flag is enabled, and `tlscacert`, `tlscert`, `tlskey`
153+
- `LimitNOFILE` and `LimitNPROC` are set, but `LimitCORE` is not
154+
- iptables addition by Docker are deactivated

ansible.cfg

Lines changed: 0 additions & 2 deletions
This file was deleted.

docker.service

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
[Service]
2+
ExecStart=/usr/bin/docker daemon -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock --storage-driver overlay --tlsverify --tlscacert /etc/docker/ca.pem --tlscert /etc/docker/server.pem --tlskey /etc/docker/server-key.pem --label provider=generic
3+
MountFlags=slave
4+
LimitNOFILE=1048576
5+
LimitNPROC=1048576
6+
LimitCORE=infinity
7+
Environment=
8+
9+
[Install]
10+
WantedBy=multi-user.target

group_vars/all

Lines changed: 0 additions & 7 deletions
This file was deleted.

group_vars/download-servers

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
3+
ds_shared_group: "{{ server_shared_group }}"

group_vars/media-centers

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
mc_shared_group: "{{ server_shared_group }}"
4+
mc_user_name: "{{ server_user_name }}"

group_vars/rpi-dockers

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
# Needed for HypriotOS
4+
with_custom_hostname: False

group_vars/rpis

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
3+
# We're updating server variables for rpis
4+
5+
server_host_name: "rpi-{{ server_user_name }}"
6+
server_shared_group: "rpi-{{ server_user_name }}-shared"
7+
8+
server_user_groups: "{{ server_shared_group }},pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi,tty"

host_vars/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

hosts.dev

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
[download_servers]
1+
[download-servers]
22
vagrant ansible_host=127.0.0.1 ansible_user=vagrant ansible_port=2222 ansible_ssh_private_key_file=./.vagrant/machines/default/virtualbox/private_key

hosts.inc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
[download_servers]
1+
[servers:children]
2+
rpis
3+
4+
[rpis]
5+
127.0.0.1
6+
7+
[download-servers]
28
127.0.0.1
Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
11
---
22

3-
- name: Configure and securise any Rpi
3+
- name: Configure and securise any Debian server
44

5-
hosts: all
5+
hosts: servers
66
roles:
77
- common
88

99
become: yes
1010

1111
- name: Setup and manage a download server
1212

13-
hosts: download_servers
13+
hosts: download-servers
1414
roles:
1515
- download_server
1616

1717
become: yes
1818

1919
- name: Setup a media center
2020

21-
hosts: media_centers
21+
hosts: media-centers
2222
roles:
2323
- media_center
2424

2525
become: yes
26+
27+
- name: Setup a Docker host
28+
29+
hosts: rpi-dockers
30+
roles:
31+
- rpi_docker
32+
33+
become: yes

roles/common/defaults/main.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
---
22

3+
# Locales
4+
server_locales:
5+
- en_US.UTF-8
6+
37
# Packages
48
required_packages:
59
- ufw
610
- fail2ban # Using defaults
711
- unattended-upgrades # Using defaults
8-
- logwatch
12+
- logwatch # Using defaults
913
- rsync
1014
- htop
1115
- curl
@@ -24,6 +28,7 @@ with_custom_hostname: False
2428

2529
automount_local_devices: []
2630
automount_network_folders: []
31+
automount_group: "{{ server_shared_group|default('root') }}"
2732

2833
ssmtp_mailhub: smtp.gmail.com:587
2934
ssmtp_auth_user: "{{ ssmtp_email }}"

roles/common/tasks/automount.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,27 @@
77
- cifs-utils
88

99
- name: Create local devices folders
10-
file: dest=/mnt/{{ item.name }} state=directory mode=0770
11-
with_items: "{{ automount_network_folders }}"
10+
file: dest=/mnt/{{ item.name }} state=directory mode=0770 group={{ automount_group }}
11+
with_items: "{{ automount_local_devices }}"
1212

1313
- name: Mount local devices by label
1414
mount:
1515
name: "/mnt/{{ item.name }}"
16-
src: "LABEL={{ item.label }}"
16+
src: "UUID={{ item.uuid }}"
1717
fstype: "{{ item.type }}"
18-
opts: "gid={{ rpi_shared_group }}"
18+
opts: "auto,nofail,noatime,rw"
1919
state: mounted
2020
with_items: "{{ automount_local_devices }}"
2121

22-
- name: Create remote folders
23-
file: dest=/media/{{ item.name }} state=directory mode=0770
22+
- name: "Create remote folders for group {{ automount_group }}"
23+
file: dest=/media/{{ item.name }} state=directory mode=0770 group={{ automount_group }}
2424
with_items: "{{ automount_network_folders }}"
2525

2626
- name: Mount remote folders
2727
mount:
2828
name: "/media/{{ item.name }}"
2929
src: "{{ item.network_folder }}"
3030
fstype: "{{ item.type|default('cifs') }}"
31-
opts: "domain={{ item.domain }},username={{ item.user }},password={{ item.password }},iocharset=utf8,file_mode=0770,dir_mode=0770,noperm,_netdev"
31+
opts: "domain={{ item.domain }},username={{ item.user }},password={{ item.password }},file_mode=0770,dir_mode=0770,noperm,iocharset=utf8,_netdev"
3232
state: mounted
3333
with_items: "{{ automount_network_folders }}"

roles/common/tasks/base.yml

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
apt: upgrade=yes
88
register: upgrade_distribution
99

10-
- name: Rebooting Rpi
10+
- name: Rebooting server
1111
shell: sleep 2 && shutdown -r now "Ansible updates triggered"
1212
async: 1
1313
poll: 0
@@ -20,8 +20,8 @@
2020
when: upgrade_distribution|changed
2121

2222
- name: Setup locale
23-
lineinfile: dest=/etc/locale.gen regexp="^#{{item}}" line="{{item}}"
24-
with_items: "{{ rpi_locale }}"
23+
locale_gen: name={{item}} state=present
24+
with_items: "{{ server_locales }}"
2525
register: update_locale
2626

2727
- name: Generate locales
@@ -32,19 +32,10 @@
3232
apt: name={{ item }} state=latest
3333
with_items: "{{ required_packages }}"
3434

35-
- name: Add new group for shared items (downloads and other roles)
36-
group: state=present name={{ rpi_shared_group }}
37-
38-
- name: Create new Rpi owner
39-
user: name={{ rpi_user_name }}
40-
groups={{ rpi_shared_group }},pi,adm,dialout,cdrom,sudo,audio,video,plugdev,games,users,input,netdev,gpio,i2c,spi,tty
41-
password={{ rpi_user_password_hash }}
35+
- name: Create new server owner
36+
user: name={{ server_user_name }}
37+
groups={{ server_user_groups }}
38+
password={{ server_user_password_hash }}
4239
shell=/bin/bash
4340
append=yes
4441
state=present
45-
46-
- name: Remove pi user from sudoers
47-
lineinfile: dest=/etc/sudoers regexp="^pi ALL" state=absent backup=yes
48-
49-
- name: Limit pi's groups
50-
user: name=pi state=present groups=pi

roles/common/tasks/hostname.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
- name: Updating hostname (1/2)
4-
hostname: name={{ rpi_host_name }}
4+
hostname: name={{ server_host_name }}
55
register: hostname_change
66

77
# A second definitive update is needed on certain Rpis
@@ -14,7 +14,7 @@
1414
- name: Update /etc/hosts
1515
lineinfile: dest=/etc/hosts
1616
regexp="^127\.0\.1\.1"
17-
line="127.0.1.1{{'\t'}}{{ rpi_host_name }}"
17+
line="127.0.1.1{{'\t'}}{{ server_host_name }}"
1818
backup=yes
1919
state=present
2020

@@ -32,7 +32,7 @@
3232
setup:
3333
when: hostname_change|changed
3434

35-
- name: Rebooting Rpi
35+
- name: Rebooting server
3636
shell: sleep 2 && shutdown -r now "Ansible updates triggered"
3737
async: 1
3838
poll: 0

roles/common/tasks/main.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@
2020
when: with_vim
2121
- include: mosh.yml
2222
when: with_mosh
23+
- include: shared_group.yml
24+
when: server_shared_group is defined
2325
- include: automount.yml
2426
when: with_automount
2527
- include: zsh.yml
2628
when: with_zsh
29+
30+
# Super optionnal (may break current process if you're using the user)
31+
32+
- include: user_unsudo.yml server_unsudo_user={{ item }}
33+
with_items: "{{ server_unsudoed_users|default([]) }}"
34+
when: server_unsudoed_users is defined

roles/common/tasks/shared_group.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
3+
- name: Add new group for shared items between roles
4+
group: state=present name={{ server_shared_group }}

roles/common/tasks/ssh.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
- name: Add authorized_keys for the user
4-
authorized_key: user={{ rpi_user_name }} key="{{ lookup('file', item) }}"
4+
authorized_key: user={{ server_user_name }} key="{{ lookup('file', item) }}"
55
with_items:
66
- "{{ ssh_public_keys }}"
77

roles/common/tasks/ssmtp.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22

33
- name: Install SSMTP
4-
apt: name=ssmtp state=installed update_cache=yes
4+
apt: name=ssmtp state=installed
55

66
- name: Set up ssmtp.conf
77
template: src=ssmtp/ssmtp.conf.j2 dest=/etc/ssmtp/ssmtp.conf

roles/common/tasks/user_unsudo.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
3+
- name: "Remove {{ server_unsudo_user }} user from sudoers"
4+
lineinfile: dest=/etc/sudoers regexp="^{{ server_unsudo_user }} ALL" state=absent backup=yes
5+
6+
- name: "Limit {{ server_unsudo_user }}'s groups"
7+
user: name={{ server_unsudo_user }} state=present groups={{ server_unsudo_user }}

0 commit comments

Comments
 (0)