-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.yml
190 lines (160 loc) · 5.59 KB
/
install.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
---
- name: Install some packages
hosts: all
vars:
controller_hostname: "{{ lookup('env', 'HOSTNAME') }}"
controller_hostname_domain: "{{ lookup('env', 'HOSTNAME').split('.')[1:] | join('.') }}"
controller_domainname: "{{ lookup('env', 'DOMAINNAME') | default(controller_hostname_domain, true) }}"
tasks:
# Wait until host is ready
- name: Wait for host {{inventory_hostname}} connection
wait_for_connection:
- name: Assign random RFC1981 net prefix
set_fact:
random_net_prefix: "192.168.{{ 128 | random + 127 }}"
- name: Assign gadget net prefix from env or random default
set_fact:
gadget_net_prefix: "{{ lookup('env', 'GADGET_NET_PREFIX') | default(random_net_prefix, true) }}"
- name: Assign domain
set_fact:
gadget_net_domain: "{{ lookup('env', 'GADGET_NET_DOMAIN') | default(controller_domainname, true) }}"
# Install bridge-utils for bridging both usb ethernet interfaces
- name: install bridge-utils
package:
name: bridge-utils
state: present
# Install avahi-autoipd for zeroconf networking (ipv4ll method) on usb[0,1]
- name: install avahi-autoipd
package:
name: avahi-autoipd
state: present
# Configure mdns services for ssh/sftp
- name: Configure ssh avahi service
copy:
src: /usr/share/doc/avahi-daemon/examples/ssh.service
dest: /etc/avahi/services/
remote_src: yes
register: avahi_daemon_configuration
- name: Configure ssh avahi service
copy:
src: /usr/share/doc/avahi-daemon/examples/sftp-ssh.service
dest: /etc/avahi/services/
remote_src: yes
register: avahi_daemon_configuration
# Install dnsmasq for dhcp over br0 interface
- name: install dnsmasq
package:
name: dnsmasq
state: present
- name: Configure dnsmasq from template
template:
src: etc/dnsmasq.d/usb.conf.j2
dest: /etc/dnsmasq.d/usb.conf
register: dnsmasq_configuration
# DEBUG Clone Reflow repo
- name: Clone devuan-pi-gadgeteer repository
git:
repo: https://github.com/adam-burns/devuan-pi-gadgeteer
dest: src/devuan-pi-gadgeteer
version: master
clone: yes
update: yes
# Add loading overlay module dwc2 to cmdline.txt
- name: "Add loading overlay module dwc2 to cmdline.txt"
become: yes
become_user: root
replace:
path: /boot/cmdline.txt
regexp: '^(.*)rootwait$'
replace: '\1 rootwait modules-load=dwc2'
backup: no
register: cmdline_updated
- name: Check if dtoverlay=dwc2 is present
become: yes
become_user: root
lineinfile:
state: absent
path: "/boot/config.txt"
regexp: "^dtoverlay=dwc2"
check_mode: true
changed_when: false # This just makes things look prettier in the logs
register: check
- name: Add dtoverlay=dwc2 if not present
lineinfile:
state: present
path: "/boot/config.txt"
line: "dtoverlay=dwc2"
when: check.found == 0
- name: Check if libcomposite module is configured in /etc/modules
become: yes
become_user: root
lineinfile:
state: absent
path: "/etc/modules"
regexp: "^libcomposite"
check_mode: true
changed_when: false # This just makes things look prettier in the logs
register: check
- name: Add libcomposite if not present
lineinfile:
state: present
path: "/etc/modules"
line: "libcomposite"
when: check.found == 0
# Configure USB Network Interfaces
- name: Configure usb0 network interface
ansible.builtin.copy:
src: etc/network/interfaces.d/usb0.conf
dest: /etc/network/interfaces.d/usb0.conf
- name: Configure usb1 network interface
ansible.builtin.copy:
src: etc/network/interfaces.d/usb1.conf
dest: /etc/network/interfaces.d/usb1.conf
- name: Create br0 network config from template
template:
src: etc/network/interfaces.d/br0.conf.j2
dest: /etc/network/interfaces.d/br0.conf
register: bridge_configuration
# Change /etc/hosts entry
- name: Update the /etc/hosts file with node name
lineinfile:
path: "/etc/hosts"
regexp: ".*\t{{ansible_hostname}}"
# line: "{{ ansible_br0.ipv4.address }}\t{{ ansible_hostname }}"
line: "{{ gadget_net_prefix }}.1\t{{ ansible_hostname }}"
state: present
backup: yes
# Configure sysctl for IP forwarding
- name: configure network forwarding
ansible.builtin.copy:
src: etc/sysctl.d/30-forwarding.conf
dest: /etc/sysctl.d/30-forwarding.conf
- name: Create /var/lib/dnsmasq if it does not exist
ansible.builtin.file:
path: /var/lib/dnsmasq
state: directory
mode: '0755'
- name: Create /etc/boot.d if it does not exist
ansible.builtin.file:
path: /etc/boot.d
state: directory
mode: '0755'
- name: network masquerading set at boot
ansible.builtin.copy:
src: etc/boot.d/masquerade.nft
dest: /etc/boot.d/masquerade
mode: '0755'
- name: usb_gadget set at boot
ansible.builtin.copy:
src: etc/boot.d/usb_gadget.sh
dest: /etc/boot.d/usb_gadget
mode: '0755'
- name: install usb_gadget
ansible.builtin.copy:
src: usb_gadget
dest: /usr/local/bin/usb_gadget
mode: '0755'
- name: reboot if necessary
ansible.builtin.reboot:
reboot_timeout: 3600
when: cmdline_updated.changed