Merge "Avoid generated-groups when creating generated-groups"

This commit is contained in:
Zuul 2018-01-23 16:00:09 +00:00 committed by Gerrit Code Review
commit 929053f4a3
1 changed files with 13 additions and 1 deletions

View File

@ -24,12 +24,24 @@ echo "# This file is autogenerated" > $outfile
unset OS_CLOUD
unset OS_REGION_NAME
# Because we are generating "generated-groups", we need to work on an
# inventory without out it ... otherwise entries that have actually
# disappeared (according to /etc/ansible/hosts/openstack's live list)
# will keep coming back as "ansible --list" finds them in the
# generated-groups file. Later versions of ansible have a
# "inventory_ignore_patterns" that might help, we just copy & remove
# in a separate inventory
inv=${outdir}/hosts
mkdir ${inv}
cp /etc/ansible/hosts/* ${inv}
rm -f ${inv}/generated-groups*
IFS=$'\n'
for line in $(</etc/ansible/groups.txt); do
name=$(echo $line | cut -f1 -d' ')
pattern=$(echo $line | cut -f2 -d' ')
echo "[${name}]" >> $outfile
ansible "${pattern}" --list-hosts | egrep -v '^ +hosts \([0-9]+\):' >> $outfile
ansible -i ${inv} "${pattern}" --list-hosts | egrep -v '^ +hosts \([0-9]+\):' >> $outfile
done
cp $outfile /etc/ansible/hosts/generated-groups