From 10754df04863c4f27ee0d147cc3295d4ddda430e Mon Sep 17 00:00:00 2001
From: keshavprasadms <keshavprasadms@gmail.com>
Date: Fri, 5 Mar 2021 16:58:45 +0530
Subject: [PATCH] fix: use the IP in the sed command

---
 deploy/migrate-to-keycloak7.sh | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/deploy/migrate-to-keycloak7.sh b/deploy/migrate-to-keycloak7.sh
index f16764300..cb339215b 100644
--- a/deploy/migrate-to-keycloak7.sh
+++ b/deploy/migrate-to-keycloak7.sh
@@ -6,12 +6,15 @@ echo "Get the standalone-ha.xml template file and module.xml"
 curl -sS https://raw.githubusercontent.com/project-sunbird/sunbird-devops/keycloak7/ansible/roles/keycloak-deploy/templates/standalone-ha.xml --output standalone-ha.xml
 curl -sS https://raw.githubusercontent.com/project-sunbird/sunbird-devops/keycloak7/ansible/roles/keycloak-deploy/templates/module.xml.j2 --output module.xml
 
+echo "Get the current VM IP"
+ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
+
 echo "Replace ansible variables with postgres details"
 sed -i "s/{{keycloak_postgres_host}}/$PG_HOST/g" standalone-ha.xml
 sed -i "s/{{keycloak_postgres_database}}/${PG_DB}7/g" standalone-ha.xml
 sed -i "s/{{keycloak_postgres_user}}/$PG_USER/g" standalone-ha.xml
 sed -i "s/{{keycloak_postgres_password}}/$PGPASSWORD/g" standalone-ha.xml
-sed -i "s/{{ansible_default_ipv4.address}}/$(hostname -i)/g" standalone-ha.xml
+sed -i "s/{{ansible_default_ipv4.address}}/$ip/g" standalone-ha.xml
 sed -i "s/8080/8081/g" standalone-ha.xml
 sed -i "s/\"900\"/\"3600\"/g" standalone-ha.xml
 
@@ -48,9 +51,6 @@ psql -h $PG_HOST -U $PG_USER -p 5432 -d ${PG_DB}7 -c "truncate offline_user_sess
 psql -h $PG_HOST -U $PG_USER -p 5432 -d ${PG_DB}7 -c "truncate offline_client_session"
 psql -h $PG_HOST -U $PG_USER -p 5432 -d ${PG_DB}7 -c "truncate jgroupsping" || true
 
-echo "Get the current VM IP"
-ip="$(ifconfig | grep -A 1 'eth0' | tail -1 | cut -d ':' -f 2 | cut -d ' ' -f 1)"
-
 echo "Migrate the DB to keycloak 7"
 cd keycloak-7.0.1
 bin/standalone.sh -b=$ip -bprivate=$ip --server-config standalone-ha.xml
-- 
GitLab