conflicting IDs while running highstate in multi saltenv configuration..

166 views
Skip to first unread message

Peter Guspan

unread,
Dec 14, 2023, 9:11:53 AM12/14/23
to Salt-users
Hi *,

I run to issue recently related to multiple saltenv and highstates.

I have setup like this:

Ubuntu 22.04
Default installation of salt from repos 3004.1+dfsg-2

extended master configuration by this config:

root@ub22-test:~# cat /etc/salt/master.d/saltenv.conf
file_roots:
  base:
    - /srv/salt/formulas
  test:
    - /srv/saltenv/test/formulas

top_file_merging_strategy: same


Content of /srv/ is following:

root@ub22-test:~# tree /srv/
/srv/
├── salt
│   └── formulas
│       ├── test
│       │   └── init.sls
│       └── top.sls
└── saltenv
    └── test
        └── formulas
            ├── test
            │   └── init.sls
            └── top.sls

7 directories, 4 files

root@ub22-test:~# cat /srv/salt/formulas/top.sls
base:
  '*':
    - test
root@ub22-test:~# cat /srv/saltenv/test/formulas/top.sls
test:
  '*':
    - test


Content of formula is same in both cases.. and I know that if I would change it my problems would be over.. but this is just mock and in real life I can't really change anything.. there is ton of formulas which just have conflicting IDs between environments

Highstate works for test

root@ub22-test:~# salt ub22-test state.highstate saltenv=test
ub22-test:
----------
          ID: test this is test
    Function: test.succeed_without_changes
      Result: True
     Comment: Success!
     Started: 14:01:10.935713
    Duration: 0.554 ms
     Changes:

Summary for ub22-test
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.554 ms

It also works for explicit base saltenv

root@ub22-test:~# salt ub22-test state.highstate saltenv=base
ub22-test:
----------
          ID: test this is test
    Function: test.succeed_without_changes
      Result: True
     Comment: Success!
     Started: 14:01:16.472568
    Duration: 0.37 ms
     Changes:

Summary for ub22-test
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.370 ms

But when I run it without specified saltenv.. I would expect that it would use base.. but obviously it's still trying to merge them.. despite of fact that I have top_file_merging_strategy: same in my master config.

root@ub22-test:~# salt ub22-test state.highstate
ub22-test:
    Data failed to compile:
----------
    Detected conflicting IDs, SLS IDs need to be globally unique.
    The conflicting ID is 'test this is test' and is found in SLS 'base:test' and SLS 'test:test'
ERROR: Minions returned with non-zero exit code


also show_top is showing both:

root@ub22-test:~# salt ub22-test state.show_top
ub22-test:
    ----------
    base:
        - test
    test:
        - test

How should I change my configuration so I can run highstate on base without specifying it.. and still be able to run highstate on `test` environment.. ?

Thanks a lot for your time!

Best regards,


Peter

Phipps, Thomas

unread,
Dec 14, 2023, 11:18:08 AM12/14/23
to salt-...@googlegroups.com
your expectation that when you run without saltenv is wrong. saltenv limits down to only that environments fileserver counting. but without saltenv then all environments fileservers are counted. and the top files from each are merged.

the top file is used to assign the environments files come from. so if you say `*` in all top files then yes it is going to try using files from all environments.

if you want to limit down to one environment. then you need to set saltenv either in the command or in the minion config.







--
You received this message because you are subscribed to the Google Groups "Salt-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/316262e4-2251-48e3-9c09-d4ec5fd20f99n%40googlegroups.com.

Peter Guspan

unread,
Dec 15, 2023, 1:36:53 AM12/15/23
to Salt-users
Hi Thomas,

thanks for reply. 

Meanwhile I've found way how to achieve what I wanted... I was fidling around with wrong option.

My desired behavior was achieved by this:

master config:

root@ub22-test:~# cat /etc/salt/master.d/saltenv.conf
file_roots:
  base:
    - /srv/salt/formulas
  test:
    - /srv/saltenv/test/formulas

state_top_saltenv: base

top.sls for both environments

root@ub22-test:~# cat /srv/salt/formulas/top.sls
base:
  '*':
    - test
root@ub22-test:~# cat /srv/saltenv/test/formulas/top.sls
test:
  '*':
    - test

output of show_top:

root@ub22-test:~# salt ub22-test state.show_top
ub22-test:
    ----------
    base:
        - test
root@ub22-test:~# salt ub22-test state.show_top  saltenv=base

ub22-test:
    ----------
    base:
        - test
root@ub22-test:~# salt ub22-test state.show_top  saltenv=test
ub22-test:
    ----------
    test:


ok.. here are two almost identical states .. with identical IDs in different environments:

root@ub22-test:~# cat /srv/salt/formulas/test/init.sls
{{ sls }} this is test:
test.succeed_without_changes

root@ub22-test:~# cat /srv/saltenv/test/formulas/test/init.sls
{{ sls }} this is test:
  test.fail_without_changes

so now call without without specifying saltenv:

root@ub22-test:~# salt ub22-test state.highstate test=true

ub22-test:
----------
          ID: test this is test
    Function: test.succeed_without_changes
      Result: True
     Comment: Success!
     Started: 20:46:21.216050
    Duration: 0.402 ms

     Changes:

Summary for ub22-test
------------
Succeeded: 1
Failed:    0
------------
Total states run:     1
Total run time:   0.402 ms

and here is run with specified saltenv=test

root@ub22-test:~# salt ub22-test state.highstate test=true  saltenv=test

ub22-test:
----------
          ID: test this is test
    Function: test.fail_without_changes
      Result: False
     Comment: If we weren't testing, this would be a failure!
     Started: 20:46:48.484537
    Duration: 1.709 ms

     Changes:

Summary for ub22-test
------------
Succeeded: 0
Failed:    1

------------
Total states run:     1
Total run time:   1.709 ms

This was tested on master 3004.1 and 3006.5.. works in both cases.. 

Still.. I am not completely sure why it worked, cause description of that option is bit vague and from my point of view it offer too much room for interpretation:

This option has no default value. Set it to an environment name to ensure that only the top file from that environment is considered during a highstate.

Note

Using this value does not change the merging strategy. For instance, if top_file_merging_strategy is set to merge, and state_top_saltenv is set to foo, then any sections for environments other than foo in the top file for the foo environment will be ignored. With state_top_saltenv set to base, all states from all environments in the base top file will be applied, while all other top files are ignored. The only way to set state_top_saltenv to something other than base and not have the other environments in the targeted top file ignored, would be to set top_file_merging_strategy to merge_all.


But still.. I am glad that I was able to find solution to my issue :)

Hope it helps somebody else with same issue..


Best regards,


Peter
Reply all
Reply to author
Forward
0 new messages