Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(admin): script to run arbitrary commands against fleet by tag/role and region #586

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions scripts/run-ansible-cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

LOCAL_PATH=$(dirname "${BASH_SOURCE[0]}")

if [ -z "$ENVIRONMENT" ]; then
echo "## ERROR in run-ansible-cmd.sh ENVIRONMENT must be set"
exit 2
fi

if [ -z "$ROLE" ]; then
echo "## ERROR in run-ansible-cmd.sh ROLE must be set"
exit 2
fi

if [ "$#" == "0" ]; then
echo "Usage: $0 command with parameters"
exit 1
fi

[ -z "$ORACLE_REGION" ] && ORACLE_REGION="all"

[ -z "$ANSIBLE_SSH_USER" ] && ANSIBLE_SSH_USER="$(whoami)"

[ -z "$BATCH_INVENTORY_FILE" ] && BATCH_INVENTORY_FILE="./batch-inventory"

if [ -f "$BATCH_INVENTORY_FILE" ]; then
echo "## using existing inventory file $BATCH_INVENTORY_FILE"
else
echo "## building inventory file $BATCH_INVENTORY_FILE"
echo '[all]' > ./batch-inventory
$LOCAL_PATH/node.py --role $ROLE --environment $ENVIRONMENT --oracle --oracle_only --region $ORACLE_REGION --batch > $BATCH_INVENTORY_FILE
fi

NODE_CMD="$*"
ansible -i ./batch-inventory all -a "$NODE_CMD" -u $ANSIBLE_SSH_USER --become --become-user root