e061759f8cf78d61f18ea346e3f50cd5c5fb04a3
[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           - "-dropbear"
66           - openssh-server
67           - git
68
69         openwrt_mixin:
70           # Go binaries
71           /usr/local/bin/door_client:
72             mode: 0755
73             file: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_client/door_client"
74           /usr/local/bin/door_daemon:
75             mode: 0755
76             file: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/door_daemon/door_daemon"
77           /usr/local/bin/update-keys:
78             mode: 0755
79             file: "{{ playbook_dir }}/.cache/openwrt/tuer/door_and_sensors/update-keys/update-keys"
80
81           /etc/ssh/sshd_config:
82             content: |-
83               Port 22000
84
85               AllowUsers root tuerctl tuergit
86               AuthenticationMethods publickey
87               AuthorizedKeysFile /etc/ssh/authorized_keys.d/%u
88
89               AllowAgentForwarding no
90               AllowTcpForwarding no
91               X11Forwarding no
92               UsePrivilegeSeparation sandbox
93
94           /etc/ssh/authorized_keys.d/root:
95             content: |-
96               {% for key in noc_ssh_keys %}
97               {{ key }}
98               {% endfor %}
99
100         openwrt_uci:
101           network:
102             - name: globals 'globals'
103               options:
104                 ula_prefix: fdc9:e01f:83db::/48
105
106             - name: interface 'loopback'
107               options:
108                 ifname: lo
109                 proto: static
110                 ipaddr: 127.0.0.1
111                 netmask: 255.0.0.0
112
113             - name: interface 'lan'
114               options:
115                 ifname: eth0
116                 accept_ra: 0
117                 proto: static
118                 ipaddr: 192.168.33.7
119                 netmask: 255.255.255.0
120                 gateway: 192.168.33.1
121                 dns: 192.168.33.1
122                 dns_search: realraum.at
123
124
125         openwrt_mounts:
126           - path: /run
127             src: none
128             fstype: tmpfs
129             opts: nosuid,nodev,noexec,noatime
130
131         openwrt_users:
132           tuerd: {}
133           tuergit:
134             home:  /var/tuer
135             shell: /usr/bin/git-shell
136           tuerctl:
137             shell: /bin/false # TODO fixme