Skip to content

Instantly share code, notes, and snippets.

@rafi
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafi/f55c47040f5dc88c54ad to your computer and use it in GitHub Desktop.
Save rafi/f55c47040f5dc88c54ad to your computer and use it in GitHub Desktop.
Converting Circus celery worker ini files into Ansible yaml
#!/usr/bin/env bash
echo "workers:"
find roles/ -iname 'celery*' | xargs grep -h 'watcher\|cmd' \
| gsed "s/'/\"/g" \
| gsed "s/\s*{{ ansible_nodename }}//g" \
| gsed 's/--time-limit=//' \
| gsed 's/\-[OQlnc]\s\+//g' \
| awk -F'"' '{for(i=2;i<=NF;i++)if(i%2==0)gsub(" ","_",$i);}1' OFS="\"" \
| gsed "s/{{\s/{{_/g" \
| gsed "s/\s}}/_}}/g" \
| awk '
/^\[watcher/ {
gsub(/^.*\:/,"")
gsub(/\]$/,"")
filename=$0
getline
sub(/.*-A/, "")
app=$1
concurrency=$2
queue=$3
timelimit=$6
sub(/[^"]+"/, "")
sub(/".*$/, "")
gsub(/_/, " ")
title=$0
print "# -----------------------------------------------"
print "- filename: " filename
print " title: " title
print " queues:"
print " - " queue
print " app: " app
print " concurrency: \"" concurrency "\""
print " time_limit: " timelimit
}
' \
| gsed "s/{{_/{{ /g" \
| gsed "s/_}}/ }}/g"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment