diff --git a/ansible/openstack-pci-passthrough-setup/hosts b/ansible/openstack-pci-passthrough-setup/hosts new file mode 100644 index 0000000..3f04058 --- /dev/null +++ b/ansible/openstack-pci-passthrough-setup/hosts @@ -0,0 +1,4 @@ +[controller] + +[compute] + diff --git a/ansible/openstack-pci-passthrough-setup/setup_pci_devices.yml b/ansible/openstack-pci-passthrough-setup/setup_pci_devices.yml new file mode 100644 index 0000000..332fc5f --- /dev/null +++ b/ansible/openstack-pci-passthrough-setup/setup_pci_devices.yml @@ -0,0 +1,94 @@ +--- + + - name: Setup Filter scheduler + hosts: controller + remote_user: heat-admin + tasks: + - name: filter scheduler + ini_file: + path: /etc/nova/nova.conf + option: baremetal_enabled_filters + value: "RetryFilter,AvailabilityZoneFilter,ComputeFilter,ComputeCapabilitiesFilter,ImagePropertiesFilter,ExactRamFilter,ExactDiskFilter,ExactCoreFilter,PciPassthroughFilter" + section: filter_scheduler + backup: yes + become: true + + - name: enable all filters + ini_file: + path: /etc/nova/nova.conf + option: available_filters + value: "nova.scheduler.filters.all_filters" + section: filter_scheduler + backup: yes + become: true + + - name: Setup Whitelist + hosts: all + remote_user: heat-admin + tasks: + - name: set pci device alias + ini_file: + path: /etc/nova/nova.conf + option: alias + value: '{ "vendor_id":"{{vendor_id}}", "product_id":"{{product_id}}", "device_type":"{{passthrough_type}}", "name":"{{alias}}" }' + section: pci + backup: yes + become: true + + - name: set pci device whitelist + ini_file: + path: /etc/nova/nova.conf + option: passthrough_whitelist + value: '{ "vendor_id": "{{vendor_id}}", "product_id": "{{product_id}}" }' + section: pci + backup: yes + become: true + + - name: Tempalte file because ansible can't handle quoted quotes + template: + src: find_replace.sh + dest: /tmp/find_replace.sh + + - name: Find and sub quotes because ansible does not allow \" in ini + shell: "bash /tmp/find_replace.sh" + become: true + + - name: Edit grub + hosts: compute + remote_user: heat-admin + tasks: + - name: add iommu to grub + lineinfile: + dest: /etc/default/grub + line: "GRUB_CMDLINE_LINUX=\"console=tty0 console=ttyS0,115200n8 crashkernel=auto rhgb quiet intel_iommu=on pci-stub.ids={{vendor_id}}:{{product_id}}\"" + regexp: '^GRUB_CMDLINE_LINUX' + state: present + become: true + + - name: Regenerate grub config + shell: "grub2-mkconfig -o /boot/grub2/grub.cfg" + become: true + + - name: Bounce controller nova services + hosts: all + remote_user: heat-admin + tasks: + - name: Bounce nova services + service: + name: "{{item}}" + state: restarted + become: true + with_items: + - openstack-nova-api + - openstack-nova-conductor + - openstack-nova-consoleauth + - openstack-nova-novncproxy + - openstack-nova-scheduler + + - name: reboot the computes + hosts: compute + remote_user: heat-admin + tasks: + - name: reboot + shell: reboot now + become: true diff --git a/ansible/openstack-pci-passthrough-setup/templates/find_replace.sh b/ansible/openstack-pci-passthrough-setup/templates/find_replace.sh new file mode 100644 index 0000000..dca68ca --- /dev/null +++ b/ansible/openstack-pci-passthrough-setup/templates/find_replace.sh @@ -0,0 +1,3 @@ +#!/bin/bash +sudo sed -i '/alias =/s/'\''/\"/g' /etc/nova/nova.conf +sudo sed -i '/passthrough_whitelist =/s/'\''/\"/g' /etc/nova/nova.conf diff --git a/ansible/openstack-pci-passthrough-setup/vars/all.yml b/ansible/openstack-pci-passthrough-setup/vars/all.yml new file mode 100644 index 0000000..2106f4e --- /dev/null +++ b/ansible/openstack-pci-passthrough-setup/vars/all.yml @@ -0,0 +1,12 @@ +# Use lspci -nn find the tupe of hex values xxxx:xxxx for the device you wish to pass +# this will allow all devices of that make and model to be passed through. If you need +# to pass through multiple unique devices rerun this playbook with different values +# if you want those different devices to be treated the same, use the same alias +vendor_id: +product_id: +# The identifier you will use in your flavor +alias: +# The method of passthrough used, options are type-PF (physical function) +# type-VF (virtual function) for NFV and type-PCI for everything else +# if you are trying to passthrough storage/gpu etc use type-PCI +passthrough_type: