Skip to content

Commit

Permalink
Reduce unnecessary API calls
Browse files Browse the repository at this point in the history
The role will no longer make API calls to authorize already authorized members to a network.
  • Loading branch information
m4rcu5nl committed Dec 4, 2018
1 parent c03c2b5 commit 672c67e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
13 changes: 6 additions & 7 deletions files/set_facts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ function file_content {
if [ ! -z "$NETWORKS" ]; then
echo "{"
echo " \"node_id\":\"${NODE_STATUS[2]}\","
echo " \"networks\": ["
echo " \"networks\": {"
while read -r; do
network=($REPLY)
echo " {"
echo " \"id\":\"${network[2]}\","
echo " \"status\":\"${network[5]}\""
echo " }"
echo " \"${network[2]}\": {"
echo " \"status\":\"${network[5]}\""
echo " }"
done <<< $NETWORKS
echo " ]"
echo " }"
echo "}"
else
echo "{\"node_id\":\"${NODE_STATUS[2]}\"}"
echo "{\"node_id\":\"${NODE_STATUS[2]}\",\"networks\":{}}"
fi
}

Expand Down
4 changes: 3 additions & 1 deletion tasks/authorize_node.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
- block:
- name: Authorize members to network
- name: Authorize new members to network
uri:
url: "{{ zerotier_api_url }}/api/network/{{ zerotier_network_id }}/member/{{ ansible_local.zerotier.node_id }}"
method: POST
Expand All @@ -13,6 +13,8 @@
body_format: json
register: auth_apiresult
delegate_to: "{{ zerotier_api_delegate }}"
when:
- ansible_local.zerotier.networks[zerotier_network_id] is not defined or ansible_local.zerotier.networks[zerotier_network_id].status != 'OK'

- name: Configure members in network
uri:
Expand Down

0 comments on commit 672c67e

Please sign in to comment.