Created
August 4, 2015 15:45
-
-
Save kols/1a49dae3b839006a14cd to your computer and use it in GitHub Desktop.
ansible chnroutes ipset with bestroutetb
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
--- | |
- 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 |
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
--- | |
- include: chnroutes.yml tags=chnroute |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment