I have inventory file as below,
[routers]
iLAB-SR-12-R2 ansible_host=192.168.82.211
iLAB-SR-12-R3 ansible_host=192.168.82.212
iLAB-SR-12-R4 ansible_host=192.168.82.213
And I have shell script for comparing multiple files with master file,
#!/bin/bash
config_location="/etc/ansible/test"
master="/etc/ansible/test-master"
cd $config_location
file=`ls -l | grep "^-" | awk '{print $NF}'`
echo "Hostname IpAddress Comments" > /etc/ansible/output.csv
for i in $file
do
if diff -c $i $master > "/etc/ansible/test-difference/diff_$i" ;then
echo "$i NoChange"
else
echo "$i SomeChange"
fi
done >> /etc/ansible/output.csv
The question is if it was ansible i would use {{remote_host}} to get the ipaddress for my output.csv file. In script how could i call variable {{ansible_host}} to get ipaddress or is there any way.
Below is my sample output.csv file but the ipaddress is empty now,
Hostname Ipaddress Comments
Test1 Somechanges
Test2 Nochanges
Anyone help me how to get the ipaddress from the inventory file. Thanks in advance.
file
-variable will fail you sooner or later. You should not parse ls , and I suggest naming the variable something other than "file", becausefile
is a command name. You should quote your variables, too. File names can have spaces in them...ansible -i inventoryfile all -m setup -a 'filter=ansible_all_ipv4_addresses'
will get you your ip-adresses.