-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create /etc/ansible/facts.d/zerotier.fact on each node containing custom facts in json format. This can then be used to prevent pointless reconfiguration of existing nodes whenever a new one is added to the inventory. In this commit it merely skips the installation tasks.
- Loading branch information
Showing
3 changed files
with
47 additions
and
19 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
FACTS_DIR='/etc/ansible/facts.d' | ||
FACT_FILE="${FACTS_DIR}/zerotier.fact" | ||
NODE_STATUS=($(zerotier-cli status)) | ||
NETWORKS=$(zerotier-cli listnetworks | tail -n+2) | ||
|
||
function file_content { | ||
if [ ! -z "$NETWORKS" ]; then | ||
echo "{" | ||
echo " \"node_id\":\"${NODE_STATUS[2]}\"," | ||
echo " \"networks\": [" | ||
while read -r; do | ||
network=($REPLY) | ||
echo " {" | ||
echo " \"id\":\"${network[2]}\"," | ||
echo " \"status\":\"${network[5]}\"" | ||
echo " }" | ||
done <<< $NETWORKS | ||
echo " ]" | ||
echo "}" | ||
else | ||
echo "{\"node_id\":\"${NODE_STATUS[2]}\"}" | ||
fi | ||
} | ||
|
||
if [ ! -d "$FACTS_DIR" ]; then | ||
mkdir -p $FACTS_DIR | ||
fi | ||
|
||
file_content > $FACT_FILE | ||
|
||
|
||
# TO-DO | ||
# Consider something that hadles JSON better than Bash does | ||
# The above will fail when it runs in to more than 1 network |
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
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