f0017c732f0e2848e219df3e4ae3a9a7df9254a9
[noc.git] / ansible / tuer.yml
1 ---
2 - hosts: torwaechter
3   connection: local
4   pre_tasks:
5     - name: Create go directories
6       file:
7         path: .cache/openwrt/tuer/{{ item }}
8         state: directory
9       with_items: [ gopath, gocache ]
10
11     - name: Clone necessary git repositories
12       git:
13         repo: https://github.com/realraum/{{ item }}.git
14         dest: .cache/openwrt/tuer/{{ item }}
15         update: True
16       with_items: [ door_and_sensors ]
17
18     - name: Download dependencies
19       command: go get -d ./...
20       args:
21         chdir: .cache/openwrt/tuer/door_and_sensors/{{ item }}
22       environment:
23         GOCACHE: "{{ playbook_dir }}/.cache/openwrt/tuer/gocache"
24         GOPATH:  "{{ playbook_dir }}/.cache/openwrt/tuer/gopath"
25       with_items: [ door_client, door_daemon, update-keys ]
26
27     - name: Cross-compile Go binaries
28       command: go build -ldflags "-s"
29       args:
30         chdir: .cache/openwrt/tuer/door_and_sensors/{{ item }}
31       environment:
32         GOCACHE: "{{ playbook_dir }}/.cache/openwrt/tuer/gocache"
33         GOPATH:  "{{ playbook_dir }}/.cache/openwrt/tuer/gopath"
34         GO386: 387
35         CGO_ENABLED: 0
36         GOOS: linux
37         GOARCH: 386
38       with_items: [ door_client, door_daemon, update-keys ]
39
40   roles:
41     - role: openwrt-image
42       delegate_to: localhost
43       vars:
44         openwrt_arch: x86
45         openwrt_target: geode
46         openwrt_output_image_suffixes:
47           - combined-ext4.img.gz
48           - combined-squashfs.img
49         openwrt_packages_remove:
50           - ppp
51           - ppp-mod-pppoe
52           - dnsmasq
53           - firewall
54           - odhcpd
55         openwrt_packages_add:
56           - flashrom
57           - haveged
58           - htop
59           - hwclock
60           - ip
61           - less
62           - nano
63           - tcpdump
64         openwrt_packages_extra:
65           - git
66
67         openwrt_mixin:
68           files:
69             # Go binaries
70             /usr/local/bin/door_client: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_client/door_client"
71             /usr/local/bin/door_daemon: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_daemon/door_daemon"
72             /usr/local/bin/update-keys: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/update-keys/update-keys"
73
74           content:
75             /etc/config/network: |
76               config interface 'loopback'
77                 option ifname 'lo'
78                 option proto 'static'
79                 option ipaddr '127.0.0.1'
80                 option netmask '255.0.0.0'
81
82               config globals 'globals'
83                 option ula_prefix 'fdc9:e01f:83db::/48'
84
85               config interface 'lan'
86                 option ifname 'eth0'
87                 option accept_ra '0'
88                 option proto 'static'
89                 option ipaddr  '192.168.33.7'
90                 option netmask '255.255.255.0'
91                 option gateway '192.168.33.1'
92                 option dns     '192.168.33.1'
93                 option dns_search 'realraum.at'
94
95             /etc/config/dropbear: |
96               config dropbear
97                 option PasswordAuth 'on'
98                 option RootPasswordAuth 'off'
99                 option Port '22000'
100
101             # TODO: mode needs to be 0600
102             /etc/dropbear/authorized_keys: |-
103               {% for key in noc_ssh_keys %}
104               {{ key }}
105               {% endfor %}