Pass Password:
#!/bin/bashread -sp "Enter Password: " password
echo $password | ansible-playbook -i <inventory> <playbook>
While Loop
#!/bin/bash
#read -sp "Enter Password: " password
playbook= “/home/ravi /playbooks/abc.yaml"
filename="tst_cluster.txt"
while read -r line; do
cluster=$(echo "$line" | awk -F '/' '{print $NF}' | awk -F '.yaml' '{print $1}')
echo "$line $playbook $cluster"
#echo $password | ansible-playbook -i $line $playbook --limit $cluster
echo "$line"
done < "$filename"
AWK Command to print Last word.
awk command to print the second last word
of each line in a file. Here’s a simple example:
echo "This is a sample sentence" | awk '{print $(NF-1)}'
sample
To print the word before .yaml in the
given string using awk, you can use the following command:
echo "This is a /sample/ravi.yaml" use
awk command to print before “.yaml” and after first / word
To print the word before “.yaml” and
after the last / in the given string using awk, you can use the
following command:
ravi
Assign into variable:
result=$(echo "This is a /sample/ravi.yaml" | awk -F '/' '{print $2}' | awk -F '.yaml' '{print $1}')echo $result