0

I've a task in hand where I've to run a script on all the servers behind a load balancer in aws. We have auto-scaling as well so at the time of high load, new servers get added behind the same load balancer.

The script will run to find out which git repo is set and what is the latest commit id on the server so that we can check if all the servers match the same git repo and commit id.

This is the script which will run on all the servers behind loadbalancer.

#!/usr/bin/env bash


# gets the current git branch
function parse_git_branch() {
  git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1/"
}

# get last commit hash prepended with @ (i.e. @8a323d0)
function parse_git_hash() {
  git rev-parse --short HEAD 2> /dev/null | sed "s/\(.*\)/@\1/"
}

# DEMO
GIT_BRANCH=$(parse_git_branch)$(parse_git_hash)
echo ${GIT_BRANCH}

Anyone has any idea how can I achieve this or have any previous experience with something similar? Thanks!

  • What is your question, specifically? – gf_ Aug 26 '19 at 11:18
  • use ansible with aws inventory script – c4f4t0r Aug 26 '19 at 12:41
  • @c4f4t0r can you give me some link where I can read about it. Where can I get the aws inventory scripts? – Axel Aug 26 '19 at 12:48
  • @gf_ 1. Get list of all servers behind load balancer. 2. Run a common script on all those servers. – Axel Aug 26 '19 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.