Skip to content

Instantly share code, notes, and snippets.

@kols
Created August 4, 2015 15:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kols/1a49dae3b839006a14cd to your computer and use it in GitHub Desktop.
Save kols/1a49dae3b839006a14cd to your computer and use it in GitHub Desktop.
ansible chnroutes ipset with bestroutetb
---
- name: generate chnroutes
shell: >
bestroutetb -p custom --rule-format=$'%prefix/%length\n' --group-header=$'---%name-start\n' --group-footer=$'---%name-end\n' --group-gateway -s -f -o /tmp/chnroutes.txt
&& sed -i '' -e '/---vpn-start/,/---vpn-end/d' -e '/^---/d' /tmp/chnroutes.txt
delegate_to: localhost
- name: upload chnroutes.txt
copy: src=/tmp/chnroutes.txt dest=/opt/scripts/chnroutes.txt
register: uploaded
- name: update ipset
shell: >
ipset -q create chnroute "hash:net" || true
&& ipset create chnroute_new "hash:net"
&& while read rule; do
ipset add chnroute_new $rule;
done </opt/scripts/chnroutes.txt
&& ipset swap chnroute_new chnroute
&& ipset destroy chnroute_new
when: uploaded.changed
---
- include: chnroutes.yml tags=chnroute
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment