aboutsummaryrefslogtreecommitdiff
path: root/share/hydra
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2018-05-27 12:23:32 -0300
committerSilvio Rhatto <rhatto@riseup.net>2018-05-27 12:23:32 -0300
commit7017d1dad0c88844d35ac8ff2b7735d6ea9e4f34 (patch)
tree5fe6d46f9b0551c9ab3d628795c7228802376502 /share/hydra
parent8870751d26e11afd592d85f85c3f236ceb8d903c (diff)
downloadhydra-7017d1dad0c88844d35ac8ff2b7735d6ea9e4f34.tar.gz
hydra-7017d1dad0c88844d35ac8ff2b7735d6ea9e4f34.tar.bz2
Nodes: support for chosing node config backend between puppet and ansible
Diffstat (limited to 'share/hydra')
-rwxr-xr-xshare/hydra/nodes42
1 files changed, 26 insertions, 16 deletions
diff --git a/share/hydra/nodes b/share/hydra/nodes
index fff3549..c75d5d3 100755
--- a/share/hydra/nodes
+++ b/share/hydra/nodes
@@ -17,7 +17,7 @@
# <http://www.gnu.org/licenses/>.
# Get a list of puppet node files
-function hydra_node_files_puppet {
+function hydra_node_puppet_files {
if [ -d "$PUPPET/config/node/" ]; then
#FILES="$PUPPET/config/node/*"
FILES="`ls -1 $PUPPET/config/node/ | grep -v example.org | xargs`"
@@ -25,27 +25,20 @@ function hydra_node_files_puppet {
}
# Return node names from puppet config
-function hydra_nodes_puppet {
+function hydra_nodes_puppet_names {
for file in $FILES; do
basename $file .yaml
done
}
-# Load
-source $APP_BASE/lib/hydra/functions || exit 1
-hydra_config_load
-
-# Command line arguments
-CLASS="$1"
-
-# Validation
-if ! [ -z "$PUPPET" ]; then
+# Return nodes from puppet config
+function hydra_nodes_puppet {
# Get initial file list
- hydra_node_files_puppet
+ hydra_node_puppet_files
# Get nodes
if [ ! -z "$CLASS" ]; then
- hydra_nodes_puppet | while read node; do
+ hydra_nodes_puppet_names | while read node; do
find $PUPPET/config -name "$node.yaml"
done | while read candidate; do
if grep -e "$CLASS" $candidate | grep -qe "^nodo::role"; then
@@ -53,14 +46,31 @@ if ! [ -z "$PUPPET" ]; then
fi
done
else
- hydra_nodes_puppet
+ hydra_nodes_puppet_names
fi
-elif [ -d "$HYDRA_FOLDER/ansible" ]; then
+}
+
+# Return nodes from ansible config
+function hydra_nodes_ansible {
if [ -z "$CLASS" ]; then
CLASS="all"
fi
- ANSIBLE_CONFIG=$HYDRA_FOLDER/ansible/ansible.cfg ansible -i inventories $CLASS --list-hosts | grep -v "^ hosts (" | sed -e 's/^ //'
+ hydra $HYDRA ansible $CLASS --list-hosts | grep -v "^ hosts (" | sed -e 's/^ //'
+}
+
+# Load
+source $APP_BASE/lib/hydra/functions || exit 1
+hydra_config_load
+
+# Command line arguments
+CLASS="$1"
+
+# Validation
+if ! [ -z "$PUPPET" ] && [ "$BACKEND" != "ansible" ]; then
+ hydra_nodes_puppet
+elif [ -d "$HYDRA_FOLDER/ansible" ]; then
+ hydra_nodes_ansible
else
echo "No PUPPET parameter defined at $HYDRA preferences or ansible config available."
exit 1