-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhost.yml
244 lines (194 loc) · 6.93 KB
/
host.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
---
- hosts: localhost
tasks:
- name: Add key to ansible repo
shell: GIT_DIR=/opt/ansible/.git GIT_WORK_TREE=/opt/ansible git config core.sshCommand "ssh -i /opt/radiohound/.ssh/id_rsa"
- name: Add git safe.directory to ansible repo
shell: GIT_DIR=/opt/ansible/.git GIT_WORK_TREE=/opt/ansible git config --add safe.directory /opt/ansible
- name: Get Jetson Model from /proc/device-tree/model
ansible.builtin.command: cat /proc/device-tree/model
register: jetson_model
- name: Check Orin Nano
ansible.builtin.set_fact:
jetson_board: "orin_nano"
when: "'Orin Nano Developer' in jetson_model.stdout"
- name: Check Orin Nano NX
ansible.builtin.set_fact:
jetson_board: "orin_nx"
when: "'Orin NX' in jetson_model.stdout"
- name: copy authorized_keys to root
copy:
src: "files/root_authorized_keys"
dest: /root/.ssh/authorized_keys
mode: 0600
owner: root
group: root
- name: Remove Ubuntu's Network Manager
apt:
pkg:
- network-manager
state: absent
update_cache: no
- name: Install ifupdown to manage network
apt:
pkg:
- ifupdown
state: present
update_cache: no
- name: copy udev 70-persistent-net.rules
copy:
src: "files/70-persistent-net.rules"
dest: /etc/udev/rules.d/70-persistent-net.rules
mode: 0755
owner: root
group: root
- name: copy /etc/network/interfaces
copy:
src: "files/interfaces"
dest: /etc/network/interfaces
mode: 0755
owner: root
group: root
- name: Allow udev to set interface names
lineinfile:
path: /usr/lib/systemd/network/99-default.link
state: present
regexp: '^NamePolicy=keep'
line: 'NamePolicy=database keep kernel onboard slot path'
- name: Gather network interfaces
shell: ifconfig
register: network_interfaces
- name: Set MAC address for each interface
shell: ifconfig eth1 hw ether $(ethtool -P eth1 | awk '{print $3}')
when: "'eth1' in network_interfaces.stdout"
ignore_errors: yes
# We want to use the first on-board network's mac address as our unique ID,
# but the Jetpack deployment process was cloning eth0's mac to everyone
# Use eth1, but since we rename them via udev, also check for en0
- name: Get hostname based on eth1
shell: cat /sys/class/net/eth1/address | sed -e 's/://g' | cut -c 9-12
when: "'eth1' in network_interfaces.stdout"
register: eth1_hostname
- name: Set hostname variable
set_fact:
hostname: "{{ eth1_hostname.stdout }}"
when: eth1_hostname is changed
- name: Get hostname based on en0
shell: cat /sys/class/net/en0/address | sed -e 's/://g' | cut -c 9-12
when: "'en0' in network_interfaces.stdout"
register: en0_hostname
- name: Set hostname variable
set_fact:
hostname: "{{ en0_hostname.stdout }}"
when: en0_hostname is changed
- name: Update hostname (systemd)
hostname:
name: "{{ hostname }}"
- copy: content="{{ hostname }}" dest=/etc/hostname
- name: Setup firewall
shell: |
iptables-legacy -t nat -A POSTROUTING -o en0 -j MASQUERADE
iptables-legacy -A FORWARD -i eth0 -o en1 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables-legacy -A FORWARD -i eth1 -o en0 -j ACCEPT
- name: Ensure sysctl.conf has the correct values
lineinfile:
path: /etc/sysctl.conf
state: present
regexp: '^{{ item.key }}'
line: '{{ item.key }}={{ item.value }}'
loop:
- { key: 'net.core.rmem_default', value: '26214400' }
- { key: 'net.core.rmem_max', value: '104857600' }
- { key: 'net.core.wmem_default', value: '65536' }
- { key: 'net.core.wmem_max', value: '104857600' }
- { key: 'net.ipv4.ip_forward', value: '1' }
- name: Apply sysctl settings
command: sysctl -p
# - name: Set ethtool ring buffer sizes
# command: ethtool -G eth2 rx 8192 tx 8192
# ignore_errors: yes
# - name: Set MTU to 9000 on eth0
# command:
# cmd: ip link set dev eth0 mtu 9000
# ignore_errors: yes
# notify:
# - Restart networking
###### eth0 ######
# - name: Check if eth0 has the IP address 192.168.4.1
# command:
# cmd: ip addr show dev eth0
# ignore_errors: yes
# register: eth0_output
# - name: Check for eth0-connection
# command: nmcli connection show
# when: "'192.168.4.1' not in eth0_output.stdout"
# register: eth0_connection
# - name: Add a new connection for eth0
# command: nmcli con add type ethernet ifname eth0 con-name eth0-connection
# when: "'192.168.4.1' not in eth0_output.stdout and 'eth0-connection' not in eth0_connection"
# - name: Set IP address for eth0
# command: nmcli con mod eth0-connection ipv4.addresses "192.168.4.1/24"
# ignore_errors: yes
# when: "'192.168.4.1' not in eth0_output.stdout"
# notify:
# - Restart networking
# - name: Set IP method to manual
# command: nmcli con mod eth0-connection ipv4.method manual
# ignore_errors: yes
# when: "'192.168.4.1' not in eth0_output.stdout"
# notify:
# - Restart networking
# - name: Bring up the connection
# command: nmcli con up eth0-connection
# ignore_errors: yes
# when: "'192.168.4.1' not in eth0_output.stdout"
# notify:
# - Restart networking
# - name: Check if eth1 has the IP address 192.168.20.1
# command:
# cmd: ip addr show dev eth1
# ignore_errors: yes
# register: eth1_output
# - name: Add a new connection for eth0
# command: nmcli con add type ethernet ifname eth0 con-name eth0-connection
# - name: Set IP address for eth1
# command: nmcli con mod eth1-connection ipv4.addresses "192.168.20.1/24"
# ignore_errors: yes
# when: "'192.168.20.1' not in eth1_output.stdout"
# notify:
# - Restart networking
# - name: Set IP method to manual
# command: nmcli con mod eth1-connection ipv4.method manual
# ignore_errors: yes
# when: "'192.168.20.1' not in eth1_output.stdout"
# notify:
# - Restart networking
# - name: Bring up the connection
# command: nmcli con up eth1-connection
# ignore_errors: yes
# when: "'192.168.20.1' not in eth1_output.stdout"
# notify:
# - Restart networking
- name: Set kernel boot args
copy:
src: files/extlinux.conf
dest: /boot/extlinux/extlinux.conf
owner: root
group: root
- name: Check current power mode
stat:
path: /var/lib/nvpmodel/status
register: current_status
- name: Set power mode
copy:
dest: /var/lib/nvpmodel/status
content: "pmode:0003\n"
#register: need_reboot
changed_when: need_reboot.changed and current_status.stat.exists and "'pmode:0003\n' not in current_status.content"
handlers:
- name: Save iptables
command: /sbin/service iptables save
when: ansible_os_family == "RedHat"
- name: Save iptables
command: /sbin/iptables-save
when: ansible_os_family == "Debian"