77
88from lib .common import HostAddress
99
10- def load_inventory (inventory_path : Path ) -> dict [str , dict [str , list [str ]]]:
10+ def load_inventory (inventory_path : Path ) -> dict [str , dict [str , list [str ] | bool ]]:
1111 """Create an inventory object from loaded inventory file."""
12- inventory : dict [str , dict [str , list [str ]]] = {}
12+ inventory : dict [str , dict [str , list [str ] | bool ]] = {}
1313
1414 with open (inventory_path , "rb" ) as f :
1515 data = tomllib .load (f )
@@ -19,8 +19,13 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
1919
2020 inventory_hosts = {}
2121 for server , config in servers .items ():
22+ nested = config .get ("nested" , None )
23+ # We can't use 'False' as fallback value here, because 'False' is falsy...
24+ if nested is None :
25+ nested = all .get ("nested" , False )
2226 repos = config .get ("enablerepos" , [])
2327 host = {
28+ "nested" : nested ,
2429 "enablerepos" : repos or all .get ("enablerepos" , [])
2530 }
2631 inventory_hosts [server ] = host
@@ -31,17 +36,18 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
3136 return inventory
3237
3338def into_inventory (
34- hosts : list [HostAddress ], enablerepos : list [str ], parent : HostAddress
35- ) -> dict [HostAddress , dict [str , list [str ]]]:
39+ hosts : list [HostAddress ], enablerepos : list [str ], parent : HostAddress , nested : bool
40+ ) -> dict [HostAddress , dict [str , list [str ] | bool ]]:
3641 """Create an inventory object from arguments.
3742
3843 Basically, it is used as compatibility when we don't want inventory from file.
3944 """
40- inventory : dict [HostAddress , dict [str , list [str ]]] = {}
45+ inventory : dict [HostAddress , dict [str , list [str ] | bool ]] = {}
4146
4247 inventory_hosts = {}
4348 for h in hosts :
44- host : dict [str , list [str ]] = {
49+ host : dict [str , list [str ] | bool ] = {
50+ "nested" : nested or False ,
4551 "enablerepos" : enablerepos or [],
4652 }
4753 inventory_hosts [h ] = host
0 commit comments