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 )
@@ -18,23 +18,31 @@ def load_inventory(inventory_path: Path) -> dict[str, dict[str, list[str]]]:
1818 servers = data .get ("servers" , [])
1919
2020 for server , config in servers .items ():
21+ nested = config .get ("nested" , None )
22+ # We can't use 'False' as fallback value here, because 'False' is falsy...
23+ if nested is None :
24+ nested = all .get ("nested" , False )
2125 repos = config .get ("enablerepos" , [])
2226 host = {
27+ "nested" : nested ,
2328 "enablerepos" : repos or all .get ("enablerepos" , [])
2429 }
2530 inventory [server ] = host
2631
2732 return inventory
2833
29- def into_inventory (hosts : list [HostAddress ], enablerepos : list [str ]) -> dict [HostAddress , dict [str , list [str ]]]:
34+ def into_inventory (
35+ hosts : list [HostAddress ], enablerepos : list [str ], nested : bool
36+ ) -> dict [HostAddress , dict [str , list [str ] | bool ]]:
3037 """Create an inventory object from arguments.
3138
3239 Basically, it is used as compatibility when we don't want inventory from file.
3340 """
34- inventory : dict [HostAddress , dict [str , list [str ]]] = {}
41+ inventory : dict [HostAddress , dict [str , list [str ] | bool ]] = {}
3542
3643 for h in hosts :
37- host = {
44+ host : dict [str , list [str ] | bool ] = {
45+ "nested" : nested or False ,
3846 "enablerepos" : enablerepos or [],
3947 }
4048 inventory [h ] = host
0 commit comments