diff --git a/roles/generate-xorg-local/files/nvidia-xconf-gen.py b/roles/generate-xorg-local/files/nvidia-xconf-gen.py new file mode 100755 index 0000000000000000000000000000000000000000..7f25d86c2086d1873b25903d3f0ba5ad73b6ff46 --- /dev/null +++ b/roles/generate-xorg-local/files/nvidia-xconf-gen.py @@ -0,0 +1,72 @@ +#!/bin/python -E +from jinja2 import Template, Environment, FileSystemLoader +import itertools +import subprocess +import datetime +import os +import sys +import time +import socket +from subprocess import call +import re +import json + +def grab_card_ids(): + # This method runs nvidia-smi to grab the card ids, then returns a list + + if not os.path.isfile("/bin/nvidia-smi"): + print("nvidia-smi binary not found!") + exit(1) + + cmd = ["/bin/nvidia-smi", "--query-gpu=pci.bus_id","--format=csv,noheader"] + p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + + cards = [] + + for line in p.stdout.readlines(): + line = line.rstrip().split(":")[2] + pcibus_num = int(re.sub('[.:]', '', line).rstrip("0"),16) + card = "PCI:0:{}:0".format(str(pcibus_num)) + cards.append(card) + return cards + +def grab_card_boardname(): + if not os.path.isfile("/bin/nvidia-smi"): + print("nvidia-smi binary not found!") + exit(1) + + cmd = ["/bin/nvidia-smi", "--query-gpu=name","--format=csv,noheader"] + cards = [] + p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) + for line in p.stdout.readlines(): + line = line.rstrip() + cards.append(line) + return cards + +def write_xorg_conf(cards): + num_of_cards = len(cards) + 1 + boardname = (grab_card_boardname())[0] + gpus = [] + file_loader = FileSystemLoader('/opt/generate-xorg/template') + env = Environment(loader=file_loader) + template = env.get_template('xorg.conf.j2') + + for i in range(1, num_of_cards): + monitors = [] + screens = [] + res = list(itertools.combinations(cards,i)) + + for j in range(i): + monitors.append("Monitor"+str(j)) + screens.append("Screen"+str(j)) + + for card in res: + filename = "/etc/X11/xorg.conf." + str(i) + str(res.index(card)) + template.stream({'boardname':boardname,'monitors':monitors,'screens':screens,'devices':card}).dump(filename) + +if __name__ == "__main__": + + cards = grab_card_ids() + write_xorg_conf(cards) + + diff --git a/roles/generate-xorg-local/files/xorg.conf.j2 b/roles/generate-xorg-local/files/xorg.conf.j2 new file mode 100644 index 0000000000000000000000000000000000000000..dbe3c779a95564d8f8e8a27c5c96599c508950f0 --- /dev/null +++ b/roles/generate-xorg-local/files/xorg.conf.j2 @@ -0,0 +1,80 @@ +# nvidia-xconfig: X configuration file generated by nvidia-xconfig +# nvidia-xconfig: version 375.66 (buildmeister@swio-display-x86-rhel47-06) Mon May 1 15:45:32 PDT 2017 +Section "DRI" + Mode 0666 +EndSection + +Section "ServerLayout" + + #InputDevice "Keyboard0" "CoreKeyboard" + #InputDevice "Mouse0" "CorePointer" + Identifier "Layout0" + {% for screen in screens %} + {% if screens.index(screen) == 0 %} + Screen 0 "Screen{{screens.index(screen)}}" + {% else %} + Screen {{screens.index(screen)}} "Screen{{screens.index(screen)}}" RightOf "Screen{{screens.index(screen)-1}}" + {% endif %} + {% endfor %} + #InputDevice "Keyboard0" "CoreKeyboard" + #InputDevice "Mouse0" "CorePointer" +EndSection + +Section "Files" + FontPath "/usr/share/fonts/default/Type1" +EndSection + +Section "InputDevice" + + # generated from default + Identifier "Mouse0" + Driver "mouse" + Option "Protocol" "auto" + Option "Device" "/dev/input/mice" + Option "Emulate3Buttons" "no" + Option "ZAxisMapping" "4 5" +EndSection + +Section "InputDevice" + + # generated from default + Identifier "Keyboard0" + Driver "kbd" +EndSection +{% for monitor in monitors %} +Section "Monitor" + Identifier "{{monitor}}" + VendorName "Unknown" + ModelName "Unknown" + HorizSync 28.0 - 33.0 + VertRefresh 43.0 - 72.0 + Option "DPMS" +EndSection +{% endfor %} +{% for device in devices %} +Section "Device" + Identifier "Device{{devices.index(device)}}" + Driver "nvidia" + VendorName "NVIDIA Corporation" + boardname "{{boardname}}" + BusID "{{device}}" +EndSection +{% endfor %} +{% for screen in screens %} +Section "Screen" + Identifier "Screen{{screens.index(screen)}}" + Device "Device{{screens.index(screen)}}" + Monitor "Monitor{{screens.index(screen)}}" + DefaultDepth 24 + Option "ProbeAllGpus" "false" +{% if boardname == 'GRID K1' %} + Option "UseDisplayDevice" "None" +{% endif %} + SubSection "Display" + Virtual 1920 1200 + Depth 24 + EndSubSection +EndSection +{% endfor -%} + + diff --git a/roles/generate-xorg-local/tasks/main.yml b/roles/generate-xorg-local/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..8ea3de0b22705e918cfbb52a90307d73851ce734 --- /dev/null +++ b/roles/generate-xorg-local/tasks/main.yml @@ -0,0 +1,32 @@ +--- +- name: create /opt/generate-xorg and template dirs + become: yes + file: + path: /opt/generate-xorg/template + state: directory + mode: '0755' + +- name: copy nvidia-xconf-gen.py + become: yes + copy: + src: nvidia-xconf-gen.py + dest: /opt/generate-xorg/nvidia-xconf-gen.py + owner: root + mode: '0755' + +- name: copy xorg.conf.j2 template + become: yes + copy: + src: xorg.conf.j2 + dest: /opt/generate-xorg/template/xorg.conf.j2 + owner: root + mode: '0644' + +- name: Creates ansible-generate-xorg file under /etc/cron.d + become: yes + cron: + name: cron job to generate xorg after reboot + special_time: reboot + user: root + job: "/opt/generate-xorg/nvidia-xconf-gen.py" + cron_file: ansible-generate-xorg diff --git a/scripts/cloudinit.sh b/scripts/cloudinit.sh new file mode 100644 index 0000000000000000000000000000000000000000..aea33c4fad3ace0970600f2510a2ba953de69424 --- /dev/null +++ b/scripts/cloudinit.sh @@ -0,0 +1,4 @@ +#!/bin/bash +hpcca_public_key='cert-authority ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCfHlWGrnpirvqvUTySnoQK6ze5oIXz7cYIT+XCBeBCahlK05O38g0erBGrNWFozZwbIXnysVCibaUJqtH0JrYqmcr2NnYA0PoiTeranvaJI7pQsga1gBxfK/D4UItw5yI6V7w9efMT0zpIP8WEubQz6GFtkyiNVgFCHj3+VhLs3RslvYzb35SFcLXEDsGVQM5NdWBUgRaNRqpTPvuMcxTyPvy32wW72kwaYRQioDJFcE2WJ240M2oSsx+dhTWvI8sW1sEUI1qIDfyBPsOgsLofuSpt4ZNgJqBUTp/hW85wVpNzud6A4YJWHpZXSDMtUMYE9QL+x2fw/b26yck9ZPE/ hines@tun' +mkdir -p /home/ec2-user/.ssh +echo $hpcca_public_key >> /home/ec2-user/.ssh/authorized_keys