From f95cccdad394f4f33cb8212cf6aefb95df5effef Mon Sep 17 00:00:00 2001
From: polyfloyd <floyd@polyfloyd.net>
Date: Mon, 25 May 2020 14:52:06 +0200
Subject: [PATCH] bar: Set some defaults with the new raspi role

---
 bar.yaml                       |  3 +++
 roles/raspi/handlers/main.yaml |  3 +++
 roles/raspi/tasks/main.yaml    | 26 ++++++++++++++++++++++++++
 3 files changed, 32 insertions(+)
 create mode 100644 roles/raspi/handlers/main.yaml
 create mode 100644 roles/raspi/tasks/main.yaml

diff --git a/bar.yaml b/bar.yaml
index d93a1cd..1e76d91 100644
--- a/bar.yaml
+++ b/bar.yaml
@@ -1,4 +1,7 @@
 ---
 - hosts: bar
+  vars:
+    raspi_rotate_display: "2"
   roles:
+    - raspi
     - bank-terminal
diff --git a/roles/raspi/handlers/main.yaml b/roles/raspi/handlers/main.yaml
new file mode 100644
index 0000000..d25cf90
--- /dev/null
+++ b/roles/raspi/handlers/main.yaml
@@ -0,0 +1,3 @@
+---
+- name: reboot
+  reboot:
diff --git a/roles/raspi/tasks/main.yaml b/roles/raspi/tasks/main.yaml
new file mode 100644
index 0000000..8f4a667
--- /dev/null
+++ b/roles/raspi/tasks/main.yaml
@@ -0,0 +1,26 @@
+---
+- name: Check whether user pi exists
+  command: "grep ^pi: /etc/passwd"
+  changed_when: no
+  failed_when: pi_user_check.rc != 0 and pi_user_check.rc != 1
+  register: pi_user_check
+
+- name: Disable default user
+  user:
+    name: pi
+    password: !
+  when: pi_user_check.stdout_lines|length > 0
+
+- name: Enable sshd
+  systemd:
+    name: sshd
+    enabled: yes
+    state: started
+
+- name: Rotate display
+  lineinfile:
+    path: /boot/config.txt
+    line: "display_rotate={{ raspi_rotate_display }} # Managed by Ansible"
+    regexp: "^#?display_rotate"
+  when: raspi_rotate_display is defined
+  notify: reboot