Tuer firmware (WIP)
authornicoo <nicoo@realraum.at>
Fri, 4 May 2018 00:51:06 +0000 (02:51 +0200)
committernicoo <nicoo@realraum.at>
Fri, 4 May 2018 00:51:06 +0000 (02:51 +0200)
ansible/roles/openwrt-image/tasks/main.yml
ansible/tuer.yml

index a7641c2..f136f89 100644 (file)
@@ -2,18 +2,37 @@
   when: openwrt_imgbuilder_tarball is not defined
 
 - name: Create temporary build directory
-  command: mktemp -d openwrt-{{ ansible_hostname }}.XXXXXX
+  command: mktemp --tmpdir -d openwrt-{{ ansible_hostname }}.XXXXXX
   register: tmpdir
 
 - set_fact:
     openwrt_imgbuilder_dir:   "{{ tmpdir.stdout }}"
     openwrt_imgbuilder_files: "{{ tmpdir.stdout }}/files"
 
-- name: Create the directory for slipstreamed files
+- name: Create the directories for mixins
   file:
-    path: "{{ openwrt_imgbuilder_files }}"
+    path: "{{ item }}"
     state: directory
+  with_items:
+    - "{{ openwrt_imgbuilder_files }}"
+    - "{{ openwrt_mixin.files | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
+    - "{{ openwrt_mixin.content | map('dirname') | map('regex_replace', '^', openwrt_imgbuilder_files) | unique | list }}"
 
+- name: Copy mixins in place [1/2]
+  copy:
+    src: "{{ item.value }}"
+    dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
+  with_dict: "{{ openwrt_mixin.files }}"
+  loop_control:
+    label: "{{ item.key }}"
+
+- name: Copy mixins in place [2/2]
+  copy:
+    content: "{{ item.value }}"
+    dest: "{{ openwrt_imgbuilder_files }}/{{ item.key }}"
+  with_dict: "{{ openwrt_mixin.content }}"
+  loop_control:
+    label: "{{ item.key }}"
 
 - block:
 #    - unarchive:
         path: "{{ openwrt_output_dir }}"
         state: directory
 
+    - set_fact:
+        openwrt_packages: >-
+          {{ openwrt_packages_remove | map('regex_replace', '^', '-') | join(' ') }}
+          {{ openwrt_packages_add   | join(' ') }}
+          {{ openwrt_packages_extra | join(' ') }}
+
     - name: Build the OpenWrt image
-      shell: >-
+      command: >-
         make -C {{ openwrt_imgbuilder_dir }}/{{ openwrt_tarball_basename }} image
-
           FILES="{{ openwrt_imgbuilder_files }}"
-          
-          PACKAGES="
-            {% for x in openwrt_packages_remove %}-{{x}} {% endfor %}
-            {% for x in openwrt_packages_add    %} {{x}} {% endfor %}
-            {% for x in openwrt_packages_extra  %} {{x}} {% endfor %}
-          "
+          PACKAGES="{{ openwrt_packages }}"
           BIN_DIR="{{ openwrt_output_dir }}"
-          
-          {% if openwrt_extra_name is defined %}
-          EXTRA_IMAGE_NAME="{{ openwrt_extra_name }}"
-          {% endif %}
+          {% if openwrt_extra_name is defined %} EXTRA_IMAGE_NAME="{{ openwrt_extra_name }}" {% endif %}
 
 
-  always:
-    - name: Delete the temporary build directory
-      file:
-        path: "{{ openwrt_imgbuilder_dir }}"
-        state: absent
+#  always:
+#    - name: Delete the temporary build directory
+#      file:
+#        path: "{{ openwrt_imgbuilder_dir }}"
+#        state: absent
index 438a65b..a55e085 100644 (file)
@@ -1,6 +1,6 @@
 - hosts: torwaechter
   connection: local
-  tasks:
+  pre_tasks:
     - name: Create go directories
       file:
         path: .cache/openwrt/tuer/{{ item }}
@@ -14,8 +14,6 @@
         update: True
       with_items: [ door_and_sensors ]
 
-#    - name: Build update-keys
-
     - name: Download dependencies
       command: go get -d ./...
       args:
@@ -23,7 +21,7 @@
       environment:
         GOCACHE: "{{ playbook_dir }}/.cache/openwrt/tuer/gocache"
         GOPATH:  "{{ playbook_dir }}/.cache/openwrt/tuer/gopath"
-      with_items: [ door_client, door_daemon ]
+      with_items: [ door_client, door_daemon, update-keys ]
 
     - name: Cross-compile Go binaries
       command: go build -ldflags "-s"
         CGO_ENABLED: 0
         GOOS: linux
         GOARCH: 386
-      with_items: [ door_client, door_daemon ]
+      with_items: [ door_client, door_daemon, update-keys ]
 
-- hosts: torwaechter
-  connection: local
   roles:
     - role: openwrt-image
       delegate_to: localhost
           - tcpdump
         openwrt_packages_extra:
           - git
+
+        openwrt_mixin:
+          files:
+            # Go binaries
+            /usr/local/bin/door_client: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_client/door_client"
+            /usr/local/bin/door_daemon: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_daemon/door_daemon"
+            /usr/local/bin/update-keys: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/update-keys/update-keys"
+
+          content:
+            /etc/config/network: |
+              config interface 'loopback'
+               option ifname 'lo'
+               option proto 'static'
+               option ipaddr '127.0.0.1'
+               option netmask '255.0.0.0'
+              
+              config globals 'globals'
+               option ula_prefix 'fdc9:e01f:83db::/48'
+              
+              config interface 'lan'
+               option ifname 'eth0'
+               option accept_ra '0'
+               option proto 'static'
+                option ipaddr  '192.168.33.7'
+                option netmask '255.255.255.0'
+                option gateway '192.168.33.1'
+                option dns     '192.168.33.1'
+                option dns_search 'realraum.at'
+
+            /etc/config/dropbear: |
+              config dropbear
+               option PasswordAuth 'on'
+               option RootPasswordAuth 'off'
+               option Port '22000'
+
+            /etc/dropbear/authorized_keys: |-
+              {% for key in noc_ssh_keys %}
+              key
+              {% endfor %}