2022-02-13 00:10:01 +01:00
|
|
|
---
|
|
|
|
- hosts: platon.n39.eu
|
|
|
|
become: true
|
|
|
|
vars:
|
|
|
|
ansible_python_interpreter: /usr/bin/python3
|
2022-02-19 16:30:40 +01:00
|
|
|
door_open_command: '/home/pi/sesame-open.sh'
|
2022-02-13 00:10:01 +01:00
|
|
|
ble_keykeeper_dir: '/home/pi/netz39_ble_keykeeper'
|
|
|
|
roles:
|
2022-02-19 16:30:40 +01:00
|
|
|
- role: ble-keykeeper-role
|
2022-07-23 16:16:33 +02:00
|
|
|
|
|
|
|
tasks:
|
|
|
|
- name: Install packages needed for the system
|
|
|
|
# This is a list of all packages,
|
|
|
|
# unless they are installed by a specific role
|
|
|
|
ansible.builtin.apt:
|
|
|
|
state: present
|
|
|
|
name:
|
|
|
|
# Should come from ble-keeper-role
|
|
|
|
# see https://github.com/netz39/ble-keykeeper-role/issues/4
|
|
|
|
- python3-pip
|
2022-07-23 20:29:48 +02:00
|
|
|
# This is needed for the user-executed tasks
|
|
|
|
- acl
|
2022-07-23 17:37:45 +02:00
|
|
|
# Regular packages
|
|
|
|
- tmux
|
2022-07-23 18:22:04 +02:00
|
|
|
- git-core
|
2022-07-23 18:41:38 +02:00
|
|
|
- cmake
|
2022-07-23 18:22:04 +02:00
|
|
|
- libmosquitto-dev
|
2022-07-23 18:41:38 +02:00
|
|
|
- libconfig-dev
|
2022-07-23 18:29:50 +02:00
|
|
|
- mpg123
|
2022-07-23 18:49:46 +02:00
|
|
|
- mosquitto
|
2022-07-23 19:42:06 +02:00
|
|
|
- i2c-tools
|
2022-07-23 16:17:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
- name: Set MAC address for proper DHCP recognition
|
|
|
|
# Uses mac variable from inventory
|
|
|
|
ansible.builtin.template:
|
|
|
|
src: templates/network-interfaces-dhcp-mac.j2
|
|
|
|
dest: /etc/network/interfaces.d/platon-mac
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
2022-07-23 16:34:13 +02:00
|
|
|
|
2022-07-23 17:51:31 +02:00
|
|
|
- name: Disable IPv6
|
|
|
|
# Because it is not working....
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: files/sysctl-no-ipv6.conf
|
|
|
|
dest: /etc/sysctl.d/99-systcl-no-ipv6.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
|
2022-07-23 16:34:13 +02:00
|
|
|
|
2022-07-23 18:49:46 +02:00
|
|
|
### Mosquitto for local MQTT
|
|
|
|
|
|
|
|
- name: Local configuration for Mosquitto
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: files/platon/mosquitto-local.conf
|
|
|
|
dest: /etc/mosquitto/conf.d/platon-local.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: '0644'
|
|
|
|
notify: restart mosquitto
|
|
|
|
|
|
|
|
|
2022-07-23 16:34:13 +02:00
|
|
|
### Sesam for SSH access
|
|
|
|
#
|
|
|
|
# Make sure to provide the .ssh/authorized_keys from backup, if needed
|
|
|
|
|
|
|
|
- name: Ensure sesam user is there
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: sesam
|
|
|
|
shell: /home/sesam/door-open.sh
|
|
|
|
groups: i2c
|
|
|
|
append: yes
|
2022-07-23 20:10:37 +02:00
|
|
|
generate_ssh_key: yes
|
|
|
|
|
|
|
|
- name: Get the SSH public key for sesam
|
|
|
|
ansible.builtin.slurp:
|
|
|
|
src: /home/sesam/.ssh/id_rsa.pub
|
|
|
|
register: sesam_key
|
|
|
|
|
|
|
|
- name: Add SSH public identity as authorized key to pi
|
|
|
|
ansible.posix.authorized_key:
|
|
|
|
user: "{{ gatekeeper_user }}"
|
|
|
|
state: present
|
|
|
|
key: "{{ sesam_key['content'] | b64decode }}"
|
|
|
|
comment: "Sesam access"
|
2022-07-23 16:34:13 +02:00
|
|
|
|
|
|
|
- name: Copy door-open.ssh for sesam
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: files/platon/sesam-door-open.sh
|
|
|
|
dest: /home/sesam/door-open.sh
|
2022-07-23 20:10:37 +02:00
|
|
|
owner: sesam
|
|
|
|
group: sesam
|
|
|
|
mode: "0755"
|
2022-07-23 17:35:08 +02:00
|
|
|
|
|
|
|
|
|
|
|
### Gatekeeper user (pi for now)
|
|
|
|
#
|
|
|
|
# All the gatekeeping / door control stuff is here!
|
|
|
|
|
|
|
|
- name: Ensure gatekeeper user is there
|
|
|
|
ansible.builtin.user:
|
|
|
|
name: "{{ gatekeeper_user }}"
|
|
|
|
groups: dialout,audio,plugdev,input,netdev,i2c,gpio
|
|
|
|
append: yes
|
2022-07-23 17:37:45 +02:00
|
|
|
|
|
|
|
- name: Copy management scripts
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: "files/platon/{{ item }}"
|
|
|
|
dest: "/home/{{ gatekeeper_user }}/{{ item }}"
|
|
|
|
owner: "{{ gatekeeper_user }}"
|
|
|
|
group: "{{ gatekeeper_user }}"
|
|
|
|
mode: "0755"
|
|
|
|
loop:
|
|
|
|
- i2cspeed.sh
|
|
|
|
- reboot.sh
|
|
|
|
- unstuck.sh
|
|
|
|
- sesame-open.sh
|
|
|
|
|
2022-07-23 19:26:37 +02:00
|
|
|
- name: Install start-up cron
|
|
|
|
ansible.builtin.cron:
|
|
|
|
name: Start the gatekeeper services
|
|
|
|
job: "/home/{{ gatekeeper_user }}/reboot.sh"
|
|
|
|
user: "{{ gatekeeper_user }}"
|
|
|
|
special_time: reboot
|
|
|
|
|
2022-07-23 18:02:05 +02:00
|
|
|
- name: Download wiringPi library
|
2022-07-23 17:37:45 +02:00
|
|
|
# WiringPi needs to be installed, but that library seems to be
|
2022-07-23 18:02:05 +02:00
|
|
|
# obsolete. We download something and hope it works...
|
|
|
|
ansible.builtin.get_url:
|
|
|
|
url: https://project-downloads.drogon.net/wiringpi-latest.deb
|
|
|
|
dest: "/home/{{ gatekeeper_user }}/wiringpi-latest.deb"
|
|
|
|
mode: "0644"
|
|
|
|
force: no
|
|
|
|
register: wiringPi_download
|
|
|
|
|
|
|
|
- name: Install wiringPi library
|
|
|
|
ansible.builtin.apt:
|
|
|
|
state: present
|
|
|
|
deb: "/home/{{ gatekeeper_user }}/wiringpi-latest.deb"
|
|
|
|
when: wiringPi_download.changed
|
2022-07-23 18:22:04 +02:00
|
|
|
|
|
|
|
|
|
|
|
### Rollladensteuerung
|
|
|
|
|
|
|
|
- name: Clone netz39_rollladensteuerung initial checkout
|
|
|
|
# Do this as the gatekeeper user!
|
|
|
|
become: yes
|
|
|
|
become_user: "{{ gatekeeper_user }}"
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: https://github.com/netz39/rollladensteuerung.git
|
|
|
|
dest: "/home/{{ gatekeeper_user }}/netz39_rollladensteuerung"
|
|
|
|
clone: yes
|
|
|
|
update: no
|
|
|
|
|
|
|
|
- name: Compile dootstate agent
|
|
|
|
# Do this as the gatekeeper user!
|
|
|
|
become: yes
|
|
|
|
become_user: "{{ gatekeeper_user }}"
|
|
|
|
ansible.builtin.shell:
|
|
|
|
chdir: "/home/{{ gatekeeper_user }}/netz39_rollladensteuerung/raspberry/doorstate"
|
|
|
|
cmd: make
|
|
|
|
creates: "/home/{{ gatekeeper_user }}/netz39_rollladensteuerung/raspberry/doorstate/doorstate"
|
|
|
|
|
|
|
|
- name: Compile shuttercontrol
|
|
|
|
# Do this as the gatekeeper user!
|
|
|
|
become: yes
|
|
|
|
become_user: "{{ gatekeeper_user }}"
|
|
|
|
ansible.builtin.shell:
|
|
|
|
chdir: "/home/{{ gatekeeper_user }}/netz39_rollladensteuerung/raspberry/shuttercontrol"
|
|
|
|
cmd: make
|
|
|
|
creates: "/home/{{ gatekeeper_user }}/netz39_rollladensteuerung/raspberry/shuttercontrol/shuttercontrol"
|
2022-07-23 18:29:50 +02:00
|
|
|
|
|
|
|
- name: Create directory for tyr sounds
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: "/home/{{ gatekeeper_user }}/tyr/sounds"
|
|
|
|
state: directory
|
|
|
|
owner: "{{ gatekeeper_user }}"
|
|
|
|
group: "{{ gatekeeper_user }}"
|
|
|
|
mode: "0755"
|
2022-07-23 18:41:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
### MQTT Tools
|
|
|
|
|
|
|
|
- name: Clone MQTT tools (initial checkout)
|
|
|
|
# Do this as the gatekeeper user!
|
|
|
|
become: yes
|
|
|
|
become_user: "{{ gatekeeper_user }}"
|
|
|
|
ansible.builtin.git:
|
|
|
|
repo: https://github.com/penguineer/mqtt-tools.git
|
|
|
|
dest: "/home/{{ gatekeeper_user }}/mqtt-tools"
|
|
|
|
clone: yes
|
|
|
|
update: no
|
|
|
|
|
|
|
|
- name: Compile MQTT clock
|
|
|
|
# Do this as the gatekeeper user!
|
|
|
|
become: yes
|
|
|
|
become_user: "{{ gatekeeper_user }}"
|
|
|
|
ansible.builtin.shell:
|
|
|
|
warn: false
|
|
|
|
chdir: "/home/{{ gatekeeper_user }}/mqtt-tools"
|
|
|
|
cmd: |
|
|
|
|
mkdir build
|
|
|
|
cd build
|
|
|
|
cmake ..
|
|
|
|
make
|
|
|
|
cp agents/mqtt-clock ../agents/mqtt-clock
|
|
|
|
creates: "/home/{{ gatekeeper_user }}/mqtt-tools/agents/mqtt-clock"
|
2022-07-23 18:49:46 +02:00
|
|
|
|
|
|
|
|
2022-07-23 20:47:16 +02:00
|
|
|
### Syslog setup for shuttercontrol.log
|
|
|
|
|
|
|
|
- name: Make sure shuttercontrol.log exists
|
|
|
|
ansible.builtin.file:
|
|
|
|
path: /var/log/shuttercontrol.log
|
|
|
|
state: touch
|
|
|
|
|
|
|
|
- name: Copy syslog setting for shuttercontrol
|
|
|
|
ansible.builtin.copy:
|
|
|
|
src: files/platon/syslog-shuttercontrol.conf
|
|
|
|
dest: /etc/rsyslog.d/20-shuttercontrol.conf
|
|
|
|
owner: root
|
|
|
|
group: root
|
|
|
|
mode: "0644"
|
|
|
|
notify: restart rsyslog
|
|
|
|
|
2022-07-23 18:49:46 +02:00
|
|
|
handlers:
|
|
|
|
- name: restart mosquitto
|
|
|
|
service:
|
|
|
|
name: mosquitto
|
|
|
|
state: restarted
|
|
|
|
enabled: yes
|
2022-07-23 20:47:16 +02:00
|
|
|
|
|
|
|
- name: restart rsyslog
|
|
|
|
service:
|
|
|
|
name: rsyslog
|
|
|
|
state: restarted
|
|
|
|
enabled: yes
|