From 6fff5a4bad516541370a49f5f042b6f0deee9856 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 20 Dec 2017 10:29:32 +1100 Subject: [PATCH] Avoid generated-groups when creating generated-groups As explained in the comment, with the generated-groups file in the inventory, as we regenerate the groups we end up finding old entries that have actually disappeared and keep putting them back in. Change-Id: I86463ecf516c38bb08d3d45e706a0da61a33efdf --- .../files/puppetmaster/expand-groups.sh | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/openstack_project/files/puppetmaster/expand-groups.sh b/modules/openstack_project/files/puppetmaster/expand-groups.sh index 678ce0d45c..626568728f 100644 --- a/modules/openstack_project/files/puppetmaster/expand-groups.sh +++ b/modules/openstack_project/files/puppetmaster/expand-groups.sh @@ -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 $(> $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