Do not create {hostname}-host_containers group as child of other groups
The existing code adds entries like aio1-host_containers as a child group of many other container type groups in the inventory. The side effect is that the ansible magic variable group_names for a particular LXC container lists many group names associated with all of the containers on its physical host. Roles such as os_ironic create several containers and use conditional logic to deploy the correct components into each container using the contents of group_names. This does not work correctly when group_names contains all of the possible ironic container groups. This patch removes the code which adds host container groups as children of other container type groups. Removal of the {hostname}-host_containers group from each container reveals a further bug, where any belongs_to directives in env.d file container_skel sections were not processed. There is different functionality in skel_load() and container_skel_load() which is the cause of this. This patch adds a call to _parse_belongs_to() into container_skel_load() so that any groups defined with 'belongs_to' in container_skel are correctly added as children to the corresponding parent group. Change-Id: Ic76b2c211484fb107d8d23f4ef6e6cc9a4ddec4f
This commit is contained in:
parent
3e4ee68a73
commit
c76a4d5dfe
|
@ -146,9 +146,8 @@ def _parse_belongs_to(key, belongs_to, inventory):
|
||||||
|
|
||||||
|
|
||||||
def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
||||||
inventory, host_type, container_type,
|
inventory, host_type, container_host_type,
|
||||||
container_host_type, physical_host_type, config,
|
physical_host_type, config, properties, assignment):
|
||||||
properties, assignment):
|
|
||||||
"""Add in all of the host associations into inventory.
|
"""Add in all of the host associations into inventory.
|
||||||
|
|
||||||
This will add in all of the hosts into the inventory based on the given
|
This will add in all of the hosts into the inventory based on the given
|
||||||
|
@ -159,7 +158,6 @@ def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
||||||
:param type_and_name: ``str`` Combined name of host and container name
|
:param type_and_name: ``str`` Combined name of host and container name
|
||||||
:param inventory: ``dict`` Living dictionary of inventory
|
:param inventory: ``dict`` Living dictionary of inventory
|
||||||
:param host_type: ``str`` Name of the host type
|
:param host_type: ``str`` Name of the host type
|
||||||
:param container_type: ``str`` Type of container
|
|
||||||
:param container_host_type: ``str`` Type of host
|
:param container_host_type: ``str`` Type of host
|
||||||
:param physical_host_type: ``str`` Name of physical host group
|
:param physical_host_type: ``str`` Name of physical host group
|
||||||
:param config: ``dict`` User defined information
|
:param config: ``dict`` User defined information
|
||||||
|
@ -180,7 +178,6 @@ def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
||||||
|
|
||||||
if existing_count < container_affinity:
|
if existing_count < container_affinity:
|
||||||
hostvars = inventory['_meta']['hostvars']
|
hostvars = inventory['_meta']['hostvars']
|
||||||
container_mapping = inventory[container_type]['children']
|
|
||||||
address = None
|
address = None
|
||||||
|
|
||||||
if is_metal is False:
|
if is_metal is False:
|
||||||
|
@ -214,10 +211,6 @@ def _build_container_hosts(container_affinity, container_hosts, type_and_name,
|
||||||
host_type_config = config[physical_host_type][host_type]
|
host_type_config = config[physical_host_type][host_type]
|
||||||
address = host_type_config.get('ip')
|
address = host_type_config.get('ip')
|
||||||
|
|
||||||
# Create a host types containers group and append it to inventory
|
|
||||||
host_type_containers = '{}-host_containers'.format(host_type)
|
|
||||||
du.append_if(array=container_mapping, item=host_type_containers)
|
|
||||||
|
|
||||||
hostvars_options.update({
|
hostvars_options.update({
|
||||||
'ansible_host': address,
|
'ansible_host': address,
|
||||||
'container_address': address,
|
'container_address': address,
|
||||||
|
@ -408,7 +401,6 @@ def _add_container_hosts(assignment, config, container_name, container_type,
|
||||||
type_and_name,
|
type_and_name,
|
||||||
inventory,
|
inventory,
|
||||||
host_type,
|
host_type,
|
||||||
container_type,
|
|
||||||
container_host_type,
|
container_host_type,
|
||||||
physical_host_type,
|
physical_host_type,
|
||||||
config,
|
config,
|
||||||
|
@ -722,6 +714,14 @@ def container_skel_load(container_skel, inventory, config):
|
||||||
for key, value in container_skel.items():
|
for key, value in container_skel.items():
|
||||||
contains_in = value.get('contains', False)
|
contains_in = value.get('contains', False)
|
||||||
belongs_to_in = value.get('belongs_to', False)
|
belongs_to_in = value.get('belongs_to', False)
|
||||||
|
|
||||||
|
if belongs_to_in:
|
||||||
|
_parse_belongs_to(
|
||||||
|
key,
|
||||||
|
belongs_to=value['belongs_to'],
|
||||||
|
inventory=inventory
|
||||||
|
)
|
||||||
|
|
||||||
if contains_in or belongs_to_in:
|
if contains_in or belongs_to_in:
|
||||||
for assignment in value['contains']:
|
for assignment in value['contains']:
|
||||||
for container_type in value['belongs_to']:
|
for container_type in value['belongs_to']:
|
||||||
|
|
Loading…
Reference in New Issue