-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Linux: Update libvirt image to debian/bookworm64 and clab image to python:3.11-alpine #1623
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
echo -n 'Starting initial config ' && date | ||
|
||
# Set persistent hostname | ||
hostnamectl set-hostname {{ inventory_hostname }} | ||
|
||
# Update APT and install netplan | ||
apt-get update -qq | ||
apt-get install -qq nplan | ||
|
||
# (Overwrite resolved config to remove DNS stuff) | ||
cat <<SCRIPT >/etc/netplan/01-netcfg.yaml | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
eth0: | ||
dhcp4: true | ||
dhcp6: false | ||
optional: true | ||
SCRIPT | ||
netplan apply | ||
|
||
# cat <<SCRIPT > /etc/systemd/resolved.conf | ||
# [Resolve] | ||
# DNS= | ||
# FallbackDNS= | ||
# Domains= | ||
# DNSOverTLS=no | ||
# Cache=yes | ||
# DNSStubListener=yes | ||
# SCRIPT | ||
# systemctl restart systemd-resolved | ||
|
||
{% if netlab_net_tools|default(False) %} | ||
# | ||
# Install net-tools (arp, route...) | ||
# | ||
if which arp; then | ||
echo "net-tools already installed" | ||
else | ||
apt-get install -qq net-tools | ||
fi | ||
if which traceroute; then | ||
echo "traceroute already installed" | ||
else | ||
apt-get install -qq traceroute | ||
fi | ||
{% endif %} | ||
{% if netlab_lldp_enable|default(False) %} | ||
# | ||
# Enable LLDP | ||
# | ||
if systemctl is-active --quiet lldpd.service; then | ||
echo "LLDP already installed" | ||
else | ||
apt-get install -qq lldpd | ||
fi | ||
|
||
cat <<CONFIG >/etc/lldpd.d/system.conf | ||
configure lldp tx-interval 30 | ||
configure lldp tx-hold 3 | ||
configure system interface pattern *,!eth0,eth* | ||
CONFIG | ||
systemctl enable lldpd | ||
systemctl restart lldpd | ||
{% endif %} | ||
|
||
# Sysctl settings: IPv4/IPv6 forwarding, IPv6 LLA | ||
# | ||
{% set pkt_fwd = "1" if role|default("host") == "router" else "0" %} | ||
cat <<SCRIPT > /etc/sysctl.d/10-netsim.conf | ||
net.ipv4.ip_forward={{ pkt_fwd }} | ||
net.ipv6.conf.all.forwarding={{ pkt_fwd }} | ||
|
||
{% if loopback.ipv6 is defined %} | ||
net.ipv6.conf.lo.disable_ipv6=0 | ||
{% endif %} | ||
{% for l in interfaces|default([]) %} | ||
{% if l.ipv6 is defined %} | ||
net.ipv6.conf.{{ l.ifname }}.disable_ipv6=0 | ||
{% endif %} | ||
{% endfor %} | ||
|
||
SCRIPT | ||
sysctl -p /etc/sysctl.d/10-netsim.conf | ||
|
||
# Loopback addressing | ||
{% if loopback.ipv4 is defined or loopback.ipv6 is defined %} | ||
cat <<SCRIPT > /etc/netplan/02-loopback.yaml | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
lo: | ||
addresses: | ||
{% if 'ipv4' in loopback %} | ||
- {{ loopback.ipv4 }} | ||
{% endif %} | ||
{% if 'ipv6' in loopback %} | ||
- {{ loopback.ipv6 }} | ||
{% endif %} | ||
SCRIPT | ||
{% endif %} | ||
|
||
# Interface addressing | ||
{% for l in interfaces|default([]) if (l.ipv4 is defined or l.ipv6 is defined or l.dhcp is defined)%} | ||
cat <<SCRIPT > /etc/netplan/03-eth-{{ l.ifname }}.yaml | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
{{ l.ifname }}: | ||
{% if l.dhcp.client.ipv4|default(False) %} | ||
dhcp4: true | ||
{% endif %} | ||
{% if l.dhcp.client.ipv6|default(False) %} | ||
dhcp6: true | ||
{% endif %} | ||
{% for af in ('ipv4','ipv6') if af in l %} | ||
{% if loop.first %} | ||
addresses: | ||
{% endif %} | ||
- {{ l[af] }} | ||
{% endfor %} | ||
{% if l.mtu is defined %} | ||
mtu: {{ l.mtu }} | ||
{% endif %} | ||
SCRIPT | ||
{% endfor %} | ||
|
||
# Add routes to IPv4 address pools pointing to the first neighbor on the first link | ||
{% for ifdata in interfaces|default([]) if ifdata.gateway is defined %} | ||
cat <<SCRIPT > /etc/netplan/04-routes-{{ ifdata.ifname }}.yaml | ||
network: | ||
version: 2 | ||
renderer: networkd | ||
ethernets: | ||
{{ ifdata.ifname }}: | ||
routes: | ||
{% for name,pool in pools.items()|default({}) %} | ||
{% for af,pfx in pool.items() if af == 'ipv4' and name != 'mgmt' and name != 'router_id' %} | ||
- to: {{ pfx }} | ||
via: {{ ifdata.gateway.ipv4|ipaddr('address') }} | ||
{% endfor %} | ||
{% endfor %} | ||
SCRIPT | ||
{% endfor %} | ||
|
||
echo -n 'Starting netplan generate ' && date | ||
netplan generate | ||
echo -n 'Starting netplan apply ' && date | ||
nohup netplan apply & |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,7 +103,9 @@ def ssh_connect( | |
if data.netlab_ssh_args: | ||
c_args.extend(data.netlab_ssh_args.split(' ')) | ||
|
||
if data.ansible_ssh_pass: | ||
if data.ansible_ssh_private_key_file: | ||
c_args.extend(['-i', strings.eval_format(data.ansible_ssh_private_key_file,{'name': data.host})]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's wrong with passing the whole node data, and if you need the 'name' parameter, you can adjust the 'adjust_inventory_host' call to retain it. This is yet another example of the "let's fix my immediate problem" mentality. |
||
elif data.ansible_ssh_pass: | ||
c_args = ['sshpass','-p',data.ansible_ssh_pass ] + c_args | ||
|
||
if data.ansible_port: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,3 +41,6 @@ attributes: | |
uplink: str | ||
global: | ||
providers: | ||
|
||
inventory: | ||
ansible_ssh_private_key_file: .vagrant/machines/{ name }/libvirt/private_key | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is set for all Vagrant devices and probably breaks every single device that uses Vagrant default key (as in: most of them, I did a spot check on Cisco IOSv). Awesome. Just awesome. Would you once in a while stop for a microsecond, think about the wider implications of your changes, and make the minimum amount of changes necessary? |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
VAGRANT_COMMAND = ARGV[0] | ||
|
||
Vagrant.configure("2") do |config| | ||
config.ssh.insert_key = true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have 21 Vagrant boxes and most of them are not Linux and thus cannot have their SSH key replaced, and you go ahead and change the system default? Congratulations, great thinking. FWIW, according to Vagrant documentation, the "true" value is equal to the default behavior, so this was completely unnecessary, but great job anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I figured it's the system default, so this only makes explicit what's already happening. However, Vagrant has an elaborate merging process for its settings - see https://developer.hashicorp.com/vagrant/docs/vagrantfile - and so we need to make sure it's set to |
||
config.vm.provider :libvirt do |libvirt| | ||
{% if addressing.mgmt._network|default(False) %} | ||
libvirt.management_network_name = "{{ addressing.mgmt._network }}" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So you just copied the "ubuntu.j2" file, added "get netplan" and removed a few things. So when we figure out something needs to be changed and we fix it in one of the files everyone knows it has to be fixed in the other file as well, right?
There's a reason Jinja2 has "include" functionality.