Created
February 17, 2014 23:02
-
-
Save stevage/9061001 to your computer and use it in GitHub Desktop.
I just noticed the absurdity of this code I wrote yesterday. Javascript inside Python inside Bash inside Jinja inside YAML, and perilously close to a layer of regex too.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
configure_osrmweb: | |
cmd.run: | |
- cwd: /usr/share/nginx/www/osrm/WebContent | |
- name: | | |
python <<EOF | |
import os, sys, re | |
os.rename('OSRM.config.js', 'OSRM.config.js.orig') | |
# In the process we convert line endings for some reason. :/ | |
with open('OSRM.config.js.orig', 'r') as fin, open('OSRM.config.js', 'w') as fout: | |
data = fin.read() | |
data = re.sub(r'(ROUTING_ENGINES: \[).*?(\s+\],)', r'\1\n' + | |
{% for instance in tm_osrminstances %} | |
'{\n' + | |
' url: "http://{{ grains.fqdn }}:{{ instance.port}}/viaroute",\n' + | |
' timestamp: "http://{{ grains.fqdn }}:{{ instance.port}}/timestamp",\n' + | |
' metric: 1,\n' + | |
' label: "{{ instance.name }}",\n' | |
'}, \n' + | |
{% endfor %} | |
r'\2\n', data, flags=re.DOTALL) | |
fout.write(data) | |
EOF | |
echo | |
if [ "`diff OSRM.config.js OSRM.config.js.orig`" ]; then echo "changed=yes"; else echo "changed=no"; fi | |
- stateful: True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment