Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Add prepare_dev_setup role and fix lints
Browse files Browse the repository at this point in the history
  • Loading branch information
veerendra2 committed Aug 28, 2023
1 parent 914ec5a commit 1eacded
Show file tree
Hide file tree
Showing 16 changed files with 228 additions and 410 deletions.
2 changes: 2 additions & 0 deletions .ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
verbosity: 1
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: Lint
'on':
pull_request:
push:
branches:
- main

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out repo
uses: actions/checkout@v2

- name: Set up Python3
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install yamllint
run: pip3 install yamllint

- name: Run yamllint
run: |
yamllint .
- name: Run ansible-lint
uses: ansible/ansible-lint@main
7 changes: 7 additions & 0 deletions .yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
extends: default

rules:
line-length:
max: 200
level: warning
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@
![Architecture](https://user-images.githubusercontent.com/8393701/235324714-75620112-a89b-4d10-ab9d-2e44de75d36b.jpg)

## Getting Started
> :warning: **CAUTION** Ansible playbooks are highly unstable, needs to rework in future [#54](https://github.com/veerendra2/raspberrypi-homeserver/issues/54).
>
> Refer [Gitbook Docs](https://dust6765.gitbook.io/raspberrypi-home-server/) for more details and how to deploy manually
* Follow prerequisite [manual steps](https://dust6765.gitbook.io/raspberrypi-home-server/settings/manual-steps) to prepare Pi
Expand Down
16 changes: 8 additions & 8 deletions inventory.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
all:

Check warning on line 1 in inventory.yml

View workflow job for this annotation

GitHub Actions / Lint

1:1 [document-start] missing document start "---"
hosts:
atom:
ansible_ssh_port: 22
ansible_ssh_host: 192.168.0.120
ansible_ssh_user: veerendra
#ansible_ssh_password:
extra_hosts:
- "atom:192.168.0.130" # Wifi Address
# hosts:
# atom:
# ansible_ssh_port: 22
# ansible_ssh_host: 192.168.0.120
# ansible_ssh_user: veerendra
# # ansible_ssh_password:
# extra_hosts:
# - "atom:192.168.0.130" # Wifi Address
localhost:
ansible_connection: local

Check failure on line 11 in inventory.yml

View workflow job for this annotation

GitHub Actions / Lint

11:30 [new-line-at-end-of-file] no new line character at the end of file
35 changes: 12 additions & 23 deletions main.yml
Original file line number Diff line number Diff line change
@@ -1,38 +1,27 @@
# Author: Veerendra K
# Description: An Ansible playbook to make awesome Raspberry Pi homeserver

- name: Raspberry Pi Homeserver
hosts: localhost
gather_facts: yes
---
- name: Homeserver Automation
hosts: all
vars_files:
- vars.yml

pre_tasks:
- name: Run update
apt:
upgrade: true
update_cache: yes
ignore_errors: yes
become: yes

post_tasks:
- name: Run autoremove
apt:
autoremove: yes
become: yes
roles:
- veerendra2.prepare_dev_setup

tasks:
- name: Prepare Pi
import_tasks: tasks/prepare-pi.yml
ansible.builtin.import_tasks: tasks/prepare-pi.yml
become: true
tags: prepare-pi

- name: Deploy services
import_tasks: tasks/deploy-services.yml
ansible.builtin.import_tasks: tasks/deploy-services.yml
become: true
tags: services

- name: Setup firewall rules
import_tasks: tasks/ufw.yml
ansible.builtin.import_tasks: tasks/ufw.yml
become: true

- name: Performing smoke tests
import_tasks: tasks/smoke-tests.yml
ansible.builtin.import_tasks: tasks/smoke-tests.yml
tags: never
3 changes: 3 additions & 0 deletions requirements.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
roles:
- name: veerendra2.prepare_dev_setup
33 changes: 0 additions & 33 deletions tasks/bettercap.yml

This file was deleted.

10 changes: 5 additions & 5 deletions tasks/deploy-services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# https://github.com/veerendra2/raspberrypi-homeserver/issues/54

- name: Create base directory
file:
ansible.builtin.file:
path: "{{ services_base_dir_location }}"
state: directory
owner: "{{ run_user }}"
Expand All @@ -14,30 +14,30 @@
when: "'pihole' in services"

- name: Create .vpn_ip file for torrent service
copy:
ansible.builtin.copy:
dest: services/torrent/.vpn_ip
content: |
VPN_IP={{ vpn_ip }}
when: "vpn_ip and 'torrent' in services"

- name: Synchronize services directories
synchronize:
ansible.posix.synchronize:
src: "services/"
dest: "{{ services_base_dir_location }}"
delete: false
recursive: true
perms: false

- name: Create networks
docker_stack:
community.docker.docker_stack:
state: present
name: traefik
compose:
- "{{ [services_base_dir_location, 'traefik', 'network.yml'] | path_join }}"
when: "'traefik' in services"

- name: Deploy service stacks
docker_stack:
community.docker.docker_stack:
state: present
name: "{{ item }}"
compose:
Expand Down
38 changes: 0 additions & 38 deletions tasks/docker.yml

This file was deleted.

41 changes: 19 additions & 22 deletions tasks/pigpio.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
---
- name: Create temporary to pigpio build
tempfile:
ansible.builtin.tempfile:
state: directory
suffix: build
register: tempdir

- name: Download pigpio
get_url:
ansible.builtin.get_url:
url: https://github.com/joan2937/pigpio/archive/master.zip
dest: "{{ tempdir.path }}"
# TODO need to test!
- name: Extract pigpio
ansible.builtin.unarchive:
src: "{{ tempdir.path }}/master.zip"
dest: "{{ tempdir.path }}"

- name: Run make and make install pigpio
shell: |
unzip pigpio-master.zip
cd pigpio-master
sudo make
sudo make install
args:
- name: Build and install pigpio
community.general.make:
chdir: "{{ tempdir.path }}"
become: yes
target: install
params:
NUM_THREADS: 2

- name: Set systemd unit parameters for pigpiod
set_fact:
ansible.builtin.set_fact:
name: pigpiod
description: Daemon required to control GPIO pins via pigpio
exec_start_cmd: /usr/local/bin/pigpiod
Expand All @@ -32,28 +34,25 @@
service_type: forking

- name: Create pigpiod systemd unit
template:
ansible.builtin.template:
src: templates/systemd_unit.service.j2
dest: /lib/systemd/system/pigpiod.service
become: yes

- name: Enable and start pigpiod systemd daemon
systemd:
ansible.builtin.systemd:
name: pigpiod
enabled: yes
daemon_reload: yes
state: started
become: yes

- name: Copy fan.py script
copy:
ansible.builtin.copy:
src: scripts/fan.py
dest: /usr/local/bin/fan.py
mode: '0744'
become: yes

- name: Set systemd unit parameters for fan-py
set_fact:
ansible.builtin.set_fact:
name: fan-py
description: Daemon required to control fan speed via pigpio
exec_start_cmd: /usr/bin/python3 /usr/local/bin/fan.py
Expand All @@ -64,15 +63,13 @@
service_type: simple

- name: Create fan-py systemd unit
template:
ansible.builtin.template:
src: templates/systemd_unit.service.j2
dest: /lib/systemd/system/fan-py.service
become: yes

- name: Enable and start fan-py systemd daemon
systemd:
ansible.builtin.systemd:
name: fan-py
enabled: yes
daemon_reload: yes
state: started
become: yes
56 changes: 27 additions & 29 deletions tasks/pihole.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,33 @@
---
# https://github.com/pi-hole/docker-pi-hole#installing-on-ubuntu-or-fedora
- name: Configure systemd-resolved for PiHole
block:
- name: Disable stub resolver in systemd-resolved config
ini_file:
path: /etc/systemd/resolved.conf
section: Resolve
option: DNSStubListener
value: "no"
backup: true

- name: Create backup /etc/resolv.conf
copy:
remote_src: yes
src: /etc/resolv.conf
dest: /etc/resolv.conf.backup
- name: Disable stub resolver in systemd-resolved config
ini_file:
path: /etc/systemd/resolved.conf
section: Resolve
option: DNSStubListener
value: "no"
backup: true

- name: Remove /etc/resolv.conf
file:
path: /etc/resolv.conf
state: absent
- name: Create backup /etc/resolv.conf
copy:
remote_src: yes
src: /etc/resolv.conf
dest: /etc/resolv.conf.backup

- name: Create link /etc/resolv.conf
file:
src: /run/systemd/resolve/resolv.conf
dest: /etc/resolv.conf
state: link
ignore_errors: yes
- name: Remove /etc/resolv.conf
file:
path: /etc/resolv.conf
state: absent

- name: Restart systemd-resolved
service:
name: systemd-resolved
state: restarted
become: yes
- name: Create link /etc/resolv.conf
file:
src: /run/systemd/resolve/resolv.conf
dest: /etc/resolv.conf
state: link
ignore_errors: yes

- name: Restart systemd-resolved
service:
name: systemd-resolved
state: restarted
Loading

0 comments on commit 1eacded

Please sign in to comment.