Initial commit: Turbo Mothership bare metal management cluster
- k0s bootstrap with Cilium and OpenEBS - ArgoCD apps for infra, CAPI, Tinkerbell, and Netris - Ansible playbooks for virtual baremetal lab and Netris switches - CAPI provider manifests for k0smotron and Tinkerbell
This commit is contained in:
59
ansible/netris-switches/tasks/configure-switch.yml
Normal file
59
ansible/netris-switches/tasks/configure-switch.yml
Normal file
@@ -0,0 +1,59 @@
|
||||
---
|
||||
# Configure a single Cumulus switch via SSH
|
||||
|
||||
- name: "{{ switch_name }} - Set hostname"
|
||||
delegate_to: 127.0.0.1
|
||||
shell: |
|
||||
sshpass -p 'cumulus' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-p {{ switch_ssh_port }} cumulus@127.0.0.1 \
|
||||
"sudo hostnamectl set-hostname {{ switch_name }}"
|
||||
register: result
|
||||
retries: 3
|
||||
delay: 10
|
||||
until: result.rc == 0
|
||||
|
||||
- name: "{{ switch_name }} - Configure loopback IP"
|
||||
delegate_to: 127.0.0.1
|
||||
shell: |
|
||||
sshpass -p 'cumulus' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-p {{ switch_ssh_port }} cumulus@127.0.0.1 \
|
||||
"sudo nv set interface lo ip address 10.0.0.{{ switch_id + 1 }}/32 && sudo nv config apply -y"
|
||||
register: result
|
||||
retries: 3
|
||||
delay: 5
|
||||
until: result.rc == 0
|
||||
|
||||
- name: "{{ switch_name }} - Enable LLDP"
|
||||
delegate_to: 127.0.0.1
|
||||
shell: |
|
||||
sshpass -p 'cumulus' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-p {{ switch_ssh_port }} cumulus@127.0.0.1 \
|
||||
"sudo nv set service lldp && sudo nv config apply -y"
|
||||
register: result
|
||||
failed_when: false
|
||||
|
||||
- name: "{{ switch_name }} - Bring up all switch ports"
|
||||
delegate_to: 127.0.0.1
|
||||
shell: |
|
||||
sshpass -p 'cumulus' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-p {{ switch_ssh_port }} cumulus@127.0.0.1 \
|
||||
"for i in \$(seq 1 48); do sudo nv set interface swp\$i link state up 2>/dev/null; done && sudo nv config apply -y"
|
||||
register: result
|
||||
failed_when: false
|
||||
|
||||
- name: "{{ switch_name }} - Configure BGP ASN"
|
||||
delegate_to: 127.0.0.1
|
||||
vars:
|
||||
bgp_asn: "{{ 65000 + switch_id }}"
|
||||
shell: |
|
||||
sshpass -p 'cumulus' ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null \
|
||||
-p {{ switch_ssh_port }} cumulus@127.0.0.1 \
|
||||
"sudo nv set router bgp autonomous-system {{ bgp_asn }} && \
|
||||
sudo nv set router bgp router-id 10.0.0.{{ switch_id + 1 }} && \
|
||||
sudo nv config apply -y"
|
||||
register: result
|
||||
failed_when: false
|
||||
|
||||
- name: "{{ switch_name }} - Configuration complete"
|
||||
debug:
|
||||
msg: "{{ switch_name }} configured with loopback 10.0.0.{{ switch_id + 1 }}/32, ASN {{ 65000 + switch_id }}"
|
||||
83
ansible/netris-switches/tasks/create-switch-vm.yml
Normal file
83
ansible/netris-switches/tasks/create-switch-vm.yml
Normal file
@@ -0,0 +1,83 @@
|
||||
---
|
||||
# Create a single switch VM using virt-install
|
||||
|
||||
- name: "{{ switch_name }} - Check if VM exists"
|
||||
command: virsh dominfo {{ switch_name }}
|
||||
register: vm_exists
|
||||
failed_when: false
|
||||
changed_when: false
|
||||
|
||||
- name: "{{ switch_name }} - Build link list"
|
||||
set_fact:
|
||||
switch_links: []
|
||||
|
||||
- name: "{{ switch_name }} - Add links where this switch is local"
|
||||
set_fact:
|
||||
switch_links: "{{ switch_links + [{'port': link_item.local_port, 'udp_local': udp_base_port + (link_idx * 2), 'udp_remote': udp_base_port + (link_idx * 2) + 1}] }}"
|
||||
loop: "{{ topology.links }}"
|
||||
loop_control:
|
||||
loop_var: link_item
|
||||
index_var: link_idx
|
||||
label: "{{ link_item.local }}:{{ link_item.local_port }}"
|
||||
when: link_item.local == switch_name
|
||||
|
||||
- name: "{{ switch_name }} - Add links where this switch is remote"
|
||||
set_fact:
|
||||
switch_links: "{{ switch_links + [{'port': link_item.remote_port, 'udp_local': udp_base_port + (link_idx * 2) + 1, 'udp_remote': udp_base_port + (link_idx * 2)}] }}"
|
||||
loop: "{{ topology.links }}"
|
||||
loop_control:
|
||||
loop_var: link_item
|
||||
index_var: link_idx
|
||||
label: "{{ link_item.remote }}:{{ link_item.remote_port }}"
|
||||
when: link_item.remote == switch_name
|
||||
|
||||
- name: "{{ switch_name }} - Add server links"
|
||||
set_fact:
|
||||
switch_links: "{{ switch_links + [{'port': srv_item.switch_port, 'udp_local': udp_base_port + ((topology.links | length + srv_idx) * 2), 'udp_remote': udp_base_port + ((topology.links | length + srv_idx) * 2) + 1}] }}"
|
||||
loop: "{{ servers | default([]) }}"
|
||||
loop_control:
|
||||
loop_var: srv_item
|
||||
index_var: srv_idx
|
||||
label: "{{ srv_item.name }}"
|
||||
when: srv_item.connected_to == switch_name
|
||||
|
||||
- name: "{{ switch_name }} - Debug links"
|
||||
debug:
|
||||
msg: "Links for {{ switch_name }}: {{ switch_links }}"
|
||||
|
||||
- name: "{{ switch_name }} - Build virt-install command"
|
||||
set_fact:
|
||||
virt_install_cmd: >-
|
||||
virt-install
|
||||
--name {{ switch_name }}
|
||||
--vcpus {{ switch_vcpus }}
|
||||
--memory {{ switch_memory_mb }}
|
||||
--import
|
||||
--disk path={{ vm_disk_path }}/{{ switch_name }}.qcow2,bus=sata
|
||||
--graphics none
|
||||
--video none
|
||||
--osinfo detect=on,require=off
|
||||
--network none
|
||||
--controller usb,model=none
|
||||
--noautoconsole
|
||||
--qemu-commandline='-netdev user,id=mgmt,net=192.168.0.0/24,hostfwd=tcp::{{ ssh_port }}-:22'
|
||||
--qemu-commandline='-device virtio-net-pci,netdev=mgmt,mac=00:01:00:00:{{ "%02x" | format(switch_index | int) }}:00,bus=pci.0,addr=0x10'
|
||||
{% for link in switch_links %}
|
||||
--qemu-commandline='-netdev socket,udp=127.0.0.1:{{ link.udp_remote }},localaddr=127.0.0.1:{{ link.udp_local }},id={{ link.port }}'
|
||||
--qemu-commandline='-device virtio-net-pci,mac=00:02:00:{{ "%02x" | format(switch_index | int) }}:{{ "%02x" | format(loop.index) }}:{{ "%02x" | format(link.udp_local % 256) }},netdev={{ link.port }},bus=pci.0,addr=0x{{ "%x" | format(17 + loop.index0) }}'
|
||||
{% endfor %}
|
||||
|
||||
- name: "{{ switch_name }} - Create VM with virt-install"
|
||||
shell: "{{ virt_install_cmd }}"
|
||||
when: vm_exists.rc != 0
|
||||
|
||||
- name: "{{ switch_name }} - Start VM if not running"
|
||||
command: virsh start {{ switch_name }}
|
||||
register: start_result
|
||||
failed_when: start_result.rc != 0 and 'already active' not in start_result.stderr
|
||||
changed_when: start_result.rc == 0
|
||||
when: vm_exists.rc == 0
|
||||
|
||||
- name: "{{ switch_name }} - Set autostart"
|
||||
command: virsh autostart {{ switch_name }}
|
||||
changed_when: false
|
||||
Reference in New Issue
Block a user