Prevent launch-node from breaking generated groups

There are potentially two related issues here which can result in
an empty generated groups file. The first is that if there are OS_
environment variables set, then os-client-config can create an 'environ'
cloud. That cloud then, in most cases here, will not be a valid cloud
since it won't be a full config, so iterating over all existing clouds
to get their server will fail, meaning that the inventory will be empty
meaning that generated groups will then be generated empty.

To deal with that, we can consume the newer upstream option that allows
the inventory to not bail out if it has a bad cloud, but instead get all
of the resources from the clouds that do work.

Additionally though, we can do an explicit inventory run so that we can
look to see if the inventory run failed, and if so, avoid running the
expand-groups.sh script, since we'd be fairly assured that it would be
running on top of a bad inventory cache.

Change-Id: Ib18987b3083f6addc61934b435d7ecb14aa1d25a
This commit is contained in:
Monty Taylor 2016-07-07 10:16:24 -05:00
parent 5101e0fd0c
commit 3b9eda9359
No known key found for this signature in database
GPG Key ID: 7BAE94BC7141A594
2 changed files with 15 additions and 2 deletions

View File

@ -117,8 +117,20 @@ def bootstrap_server(server, key, name, volume_device, keep,
# into our inventory
# Remove cloud and region from the environment to work around a bug in occ
expand_env = os.environ.copy()
expand_env.pop('OS_CLOUD', None)
expand_env.pop('OS_REGION_NAME', None)
for env_key in expand_env.keys():
if env_key.startswith('OS_'):
expand_env.pop(env_key, None)
# Regenerate inventory cache, throwing an error if there is an issue
# so that we don't generate a bogus groups file
try:
subprocess.check_output(
['/etc/ansible/hosts/openstack', '--list'],
env=expand_env)
except subprocess.CalledProcessError as e:
print "Inventory regeneration failed"
print e.output
raise
print subprocess.check_output(
'/usr/local/bin/expand-groups.sh',

View File

@ -1,4 +1,5 @@
ansible:
fail_on_errors: False
use_hostnames: True
cache:
expiration_time: 86400