I am setting up a new infrastructure. Previous one used mod_python with the following script to handle some python work and then pass it to ipxe. On the new setup I am using mod_wsgi and I can not seem to get it to work.
Code:
<%
import requests, json, cgi
req.headers_out['Content-Type'] = 'text/plain'
req.content_type = req.headers_out['Content-Type']
ip = ""
default = ""
build = False
mac = cgi.parse_qs(req.args)["mac"][0]
r = requests.get('http://puppetnext.lab.beer.town/api/v2/hosts?search=has_mac=' + mac, auth=('user', 'password'), verify=False)
resultjson = r.json()["results"]
if len(resultjson) > 0:
hostid = resultjson[0]["id"]
hostr = requests.get('http://puppetnext.lab.beer.town/api/v2/hosts/' + str(hostid), auth=('user', 'password'), verify=False)
ip = hostr.json()["ip"]
build = hostr.json()["build"]
if ip:
if build:
default = "build"
else:
default = "local"
else:
default = "discovery"
%>#!ipxe
menu Boot options for <% req.write(mac)%>
item --key l local Continue with local boot
item --key d discovery Boot foreman discovery image
item --key b build Build local host <% req.write(ip)%>
choose --default <% req.write(default)%> --timeout 5000 target && goto ${target}
#Local
:local
exit
#Discovery
:discovery
# WORKING!!!!!!!!!!!
kernel boot/fdi-image/vmlinuz0
initrd boot/fdi-image/initrd0.img
imgargs vmlinuz0 rootflags=loop root=live:/fdi.iso rootfstype=auto ro rd.live.image acpi=force rd.luks=0 rd.md=0 rd.dm=0 rd.lvm=0 rd.bootif=0 rd.neednet=0 rd.debug=1 nomodeset BOOTIF=01-${net0/mac:hexhyp} proxy.url=http://<% req.write(req.hostname)%> proxy.type=foreman
#echo Information
#imgstat
#read void
echo Now Booting..
boot || goto failed
#iappend 2 for pxelinux is BOOTIF=01-${net0/mac:hexhyp} for iPXE
#WORKING CONFIG BUT DOES NOT AUTOMATICALLY DISCOVER WITH DHCP
#kernel http://<% req.write(req.hostname)%>:81/boot/fdi-image/vmlinuz0 rootflags=loop root=live:/fdi.iso rootfstype=auto ro rd.live.image acpi=force rd.luks=0 rd.md=0 rd.dm=0 rd.lvm=0 rd.bootif=0 rd.neednet=0 nomodeset proxy.url=https://<% req.write(req.hostname)%> proxy.type=foreman
#initrd http://<% req.write(req.hostname)%>:81/boot/fdi-image/initrd0.img
#boot
#Build
:build
chain http://<% req.write(req.hostname)%>/unattended/iPXE?mac=<% req.write(mac) %>
Before, this would execute the python script and then set the correct settings for the following ipxe script. Now I just seem to get python syntax errors.
Any idea whats going on here?
If I access it via boot.py:
Code:
[Thu Jan 04 08:40:31.583620 2018] [:error] [pid 11518] [client 100.91.160.19:55387] mod_wsgi (pid=11518): Exception occurred processing WSGI script '/usr/foremanipxe/boot.py'., referer: http://puppetnext.lab.beer.town:81/
[Thu Jan 04 08:40:31.583661 2018] [:error] [pid 11518] [client 100.91.160.19:55387] File "/usr/foremanipxe/boot.py", line 1, referer: http://puppetnext.lab.beer.town:81/
[Thu Jan 04 08:40:31.583671 2018] [:error] [pid 11518] [client 100.91.160.19:55387] <%, referer: http://puppetnext.lab.beer.town:81/
[Thu Jan 04 08:40:31.583674 2018] [:error] [pid 11518] [client 100.91.160.19:55387] ^, referer: http://puppetnext.lab.beer.town:81/
[Thu Jan 04 08:40:31.583677 2018] [:error] [pid 11518] [client 100.91.160.19:55387] SyntaxError: invalid syntax, referer: http://puppetnext.lab.beer.town:81/
If I access it via just boot:
Code:
[Thu Jan 04 08:46:24.773479 2018] [authz_core:debug] [pid 11522] mod_authz_core.c(835): [client 100.91.160.19:55457] AH01628: authorization result: granted (no directives)
[Thu Jan 04 08:46:24.780514 2018] [:info] [pid 11522] [client 100.91.160.19:55457] mod_wsgi (pid=11522, process='', application='puppet.lab.beer.town:81|/boot'): Loading WSGI script '/usr/foremanipxe/boot.py'.
[Thu Jan 04 08:46:24.780771 2018] [:error] [pid 11522] [client 100.91.160.19:55457] mod_wsgi (pid=11522, process='', application='puppet.lab.beer.town:81|/boot'): Failed to parse WSGI script file '/usr/foremanipxe/boot.py'.
[Thu Jan 04 08:46:24.780789 2018] [:error] [pid 11522] [client 100.91.160.19:55457] mod_wsgi (pid=11522): Exception occurred processing WSGI script '/usr/foremanipxe/boot.py'.
[Thu Jan 04 08:46:24.780830 2018] [:error] [pid 11522] [client 100.91.160.19:55457] File "/usr/foremanipxe/boot.py", line 1
[Thu Jan 04 08:46:24.780840 2018] [:error] [pid 11522] [client 100.91.160.19:55457] <%
[Thu Jan 04 08:46:24.780843 2018] [:error] [pid 11522] [client 100.91.160.19:55457] ^
[Thu Jan 04 08:46:24.780846 2018] [:error] [pid 11522] [client 100.91.160.19:55457] SyntaxError: invalid syntax
Conf
Code:
WSGIScriptAlias /boot /usr/foremanipxe/boot.py
<VirtualHost *:81>
ServerAdmin non@none.com
ServerName puppet.lab.beer.town
ServerAlias puppet
DocumentRoot /usr/foremanipxe
DirectoryIndex
LogLevel Debug
ErrorLog /var/log/httpd/ipxe_error.log
CustomLog /var/log/httpd/ipxe_access.log Combined
<Directory /usr/foremanipxe >
Options Indexes FollowSymLinks MultiViews ExecCGI
AllowOverride None
Order allow,deny
allow from all
</Directory>
</VirtualHost>