Browse Source

Merge "Add multistack support to tripleo-ansible-inventory"

tags/11.2.0
Zuul 2 weeks ago
parent
commit
47429ed61c
1 changed files with 36 additions and 23 deletions
  1. 36
    23
      scripts/tripleo-ansible-inventory

+ 36
- 23
scripts/tripleo-ansible-inventory View File

@@ -28,8 +28,8 @@ import traceback
28 28
 
29 29
 from oslo_config import cfg
30 30
 from six.moves import configparser
31
-
32 31
 from tripleo_common import inventory as inv
32
+from tripleo_common import inventories as invs
33 33
 from tripleo_validations import utils
34 34
 
35 35
 
@@ -46,12 +46,14 @@ opts = [
46 46
     cfg.StrOpt('project-name', default=os.environ.get(
47 47
         'OS_PROJECT_NAME', os.environ.get('OS_TENANT_NAME'))),
48 48
     cfg.StrOpt('cacert', default=os.environ.get('OS_CACERT')),
49
-    cfg.StrOpt('plan', default=os.environ.get('TRIPLEO_PLAN_NAME'),
50
-               help=('stack name to use for generating the '
51
-                     'inventory data.')),
52
-    cfg.StrOpt('stack', help=('This arg has the same effect '
53
-                              'as --plan. If both are specified, --stack '
54
-                              'will take precedence.')),
49
+    cfg.ListOpt('plan', default=os.environ.get('TRIPLEO_PLAN_NAME'),
50
+                help=('stack name(s) to use for generating the '
51
+                      'inventory data. If a comma delimited list '
52
+                      'of stacks is passed, the inventory will '
53
+                      'contain the union of those stacks.')),
54
+    cfg.ListOpt('stack', help=('This arg has the same effect '
55
+                               'as --plan. If both are specified,'
56
+                               ' --stack will take precedence.')),
55 57
     cfg.StrOpt('ansible_ssh_user', default=os.environ.get('ANSIBLE_SSH_USER',
56 58
                'heat-admin')),
57 59
     cfg.StrOpt('undercloud-connection',
@@ -132,24 +134,35 @@ def main():
132 134
         'timeout': 30
133 135
     }
134 136
 
135
-    inventory = inv.TripleoInventory(
136
-        session=utils.get_auth_session(auth_variables),
137
-        hclient=utils.get_heat_client(auth_variables),
138
-        auth_url=configs.auth_url,
139
-        cacert=configs.cacert,
140
-        project_name=configs.project_name,
141
-        username=configs.username,
142
-        ansible_ssh_user=configs.ansible_ssh_user,
143
-        plan_name=configs.stack or configs.plan,
144
-        ansible_python_interpreter=configs.ansible_python_interpreter,
145
-        undercloud_connection=configs.undercloud_connection,
146
-        undercloud_key_file=configs.undercloud_key_file,
147
-        host_network=configs.ssh_network,
148
-        serial=configs.serial)
149
-
137
+    inventory_map = {}
138
+    for _plan in (configs.stack or configs.plan):
139
+        inventory_map[_plan] = inv.TripleoInventory(
140
+            session=utils.get_auth_session(auth_variables),
141
+            hclient=utils.get_heat_client(auth_variables),
142
+            auth_url=configs.auth_url,
143
+            cacert=configs.cacert,
144
+            project_name=configs.project_name,
145
+            username=configs.username,
146
+            ansible_ssh_user=configs.ansible_ssh_user,
147
+            plan_name=_plan,
148
+            ansible_python_interpreter=configs.ansible_python_interpreter,
149
+            undercloud_connection=configs.undercloud_connection,
150
+            undercloud_key_file=configs.undercloud_key_file,
151
+            host_network=configs.ssh_network,
152
+            serial=configs.serial)
153
+
154
+    inventory_keys = inventory_map.keys()
155
+    if len(inventory_keys) == 1:
156
+        inventory = inventory_map[inventory_keys[0]]
157
+    else:
158
+        inventory = invs.TripleoInventories(inventory_map)
159
+        inventory.merge()
150 160
     if configs.list:
151 161
         try:
152
-            inventory_list = inventory.list()
162
+            if len(inventory_keys) == 1:
163
+                inventory_list = inventory.list()
164
+            else:
165
+                inventory_list = inventory.inventory
153 166
             print(json.dumps(inventory_list))
154 167
         except Exception as e:
155 168
             print("ERROR: Error creating inventory: {}".format(e),

Loading…
Cancel
Save