@@ -1473,19 +1473,37 @@ def render_state(self, sls, env, mods, matches):
1473
1473
errors .append (err )
1474
1474
else :
1475
1475
for inc_sls in state .pop ('include' ):
1476
- # Subset of my_avail containing the include sls
1477
- my_env = [
1478
- aenv for aenv in matches
1479
- if fnmatch .filter (self .avail [aenv ], inc_sls )
1480
- ]
1481
-
1482
- # An include must only be one available in one environment
1483
- # Or the include must exist in the current environment
1484
- if len (my_env ) == 1 or env in my_env :
1476
+ # inc_sls may take the form of:
1477
+ # 'sls.to.include' <- same as {<env>: 'sls.to.include'}
1478
+ # {<env_key>: 'sls.to.include'}
1479
+ # {'_xenv': 'sls.to.resolve'}
1480
+ XENV_KEY = '_xenv'
1481
+
1482
+ if isinstance (inc_sls , dict ):
1483
+ env_key , inc_sls = inc_sls .popitem ()
1484
+ else :
1485
+ env_key = env
1486
+
1487
+ if env_key != XENV_KEY :
1488
+ # Resolve inc_sls in the specified environment
1489
+ if env_key in matches and fnmatch .filter (self .avail [env_key ], inc_sls ):
1490
+ resolved_envs = [env_key ]
1491
+ else :
1492
+ resolved_envs = []
1493
+ else :
1494
+ # Resolve inc_sls in the subset of environment matches
1495
+ resolved_envs = [
1496
+ aenv for aenv in matches
1497
+ if fnmatch .filter (self .avail [aenv ], inc_sls )
1498
+ ]
1499
+
1500
+ # An include must be resolved to a single environment, or
1501
+ # the include must exist in the current environment
1502
+ if len (resolved_envs ) == 1 or env in resolved_envs :
1485
1503
if inc_sls not in mods :
1486
1504
nstate , mods , err = self .render_state (
1487
1505
inc_sls ,
1488
- my_env [0 ] if len (my_env ) == 1 else env ,
1506
+ resolved_envs [0 ] if len (resolved_envs ) == 1 else env ,
1489
1507
mods ,
1490
1508
matches
1491
1509
)
@@ -1495,14 +1513,18 @@ def render_state(self, sls, env, mods, matches):
1495
1513
errors += err
1496
1514
else :
1497
1515
msg = ''
1498
- if not my_env :
1499
- msg = ('Unknown include: Specified SLS {0} is not available on the salt master '
1500
- 'in any available environments {1} '
1501
- ).format (inc_sls , ', ' .join (matches ))
1502
- elif len (my_env ) > 1 :
1503
- msg = ('Ambiguous include: Specified SLS {0} is available on the salt master '
1504
- 'in available environments {1}'
1505
- ).format (inc_sls , ', ' .join (my_env ))
1516
+ if not resolved_envs :
1517
+ msg = ('Unknown include: Specified SLS {0}: {1} is not available on the salt '
1518
+ 'master in environment(s): {2} '
1519
+ ).format (env_key ,
1520
+ inc_sls ,
1521
+ ', ' .join (matches ) if env_key == XENV_KEY else env_key )
1522
+ elif len (resolved_envs ) > 1 :
1523
+ msg = ('Ambiguous include: Specified SLS {0}: {1} is available on the salt master '
1524
+ 'in multiple available environments: {2}'
1525
+ ).format (env_key ,
1526
+ inc_sls ,
1527
+ ', ' .join (resolved_envs ))
1506
1528
log .error (msg )
1507
1529
if self .opts ['failhard' ]:
1508
1530
errors .append (msg )
0 commit comments