From 3b9eda935903bc6bf8e833df7b593962ec744612 Mon Sep 17 00:00:00 2001 From: Monty Taylor Date: Thu, 7 Jul 2016 10:16:24 -0500 Subject: [PATCH] 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 --- launch/launch-node.py | 16 ++++++++++++++-- .../puppetmaster/ansible-clouds.yaml.erb | 1 + 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/launch/launch-node.py b/launch/launch-node.py index c33771936b..f5812cd14d 100755 --- a/launch/launch-node.py +++ b/launch/launch-node.py @@ -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', diff --git a/modules/openstack_project/templates/puppetmaster/ansible-clouds.yaml.erb b/modules/openstack_project/templates/puppetmaster/ansible-clouds.yaml.erb index 858c2d2260..3a463217d3 100644 --- a/modules/openstack_project/templates/puppetmaster/ansible-clouds.yaml.erb +++ b/modules/openstack_project/templates/puppetmaster/ansible-clouds.yaml.erb @@ -1,4 +1,5 @@ ansible: + fail_on_errors: False use_hostnames: True cache: expiration_time: 86400