File tree 1 file changed +22
-2
lines changed
1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
# https://github.com/mtecer/terraform/blob/master/bmc/files/ansible/custom.fact
4
4
5
- PUBLIC_IP=$( curl --connect-timeout 2.37 -s -4 https://ipv4.icanhazip.com)
6
- PUBLIC_IPv6=$( curl --connect-timeout 2.37 -s -6 https://ipv6.icanhazip.com)
5
+ RES=$( curl -s -w " %{http_code}" --connect-timeout 2.37 -4 https://ipify.saltbox.dev)
6
+ BODY=${RES::- 3}
7
+ STATUS=$( printf " %s" " $RES " | tail -c 3)
8
+ if [[ " $STATUS " == 200 ]]; then
9
+ # Server returned 200 response
10
+ PUBLIC_IP=$BODY
11
+ else
12
+ # Server didn't return 200 response, so falling back to icanhazip.com
13
+ PUBLIC_IP=$( curl --connect-timeout 2.37 -s -4 https://ipv4.icanhazip.com)
14
+ fi
15
+
16
+ RES6=$( curl -s -w " %{http_code}" --connect-timeout 2.37 -6 https://ipify6.saltbox.dev)
17
+ BODY6=${RES6::- 3}
18
+ STATUS6=$( printf " %s" " $RES6 " | tail -c 3)
19
+ if [[ " $STATUS " == 200 ]]; then
20
+ # Server returned 200 response
21
+ PUBLIC_IPv6=$BODY6
22
+ else
23
+ # Server didn't return 200 response, so falling back to icanhazip.com
24
+ PUBLIC_IPv6=$( curl --connect-timeout 2.37 -s -6 https://ipv6.icanhazip.com)
25
+ fi
26
+
7
27
echo " [ip]"
8
28
echo " public_ip=${PUBLIC_IP} "
9
29
echo " public_ipv6=${PUBLIC_IPv6} "
You can’t perform that action at this time.
0 commit comments