salt states duplicate key detection
Refer to discussion https://groups.google.com/forum/#!topic/salt-users/uCh0lWSS78g Need to detect duplicate keys and alert accordingly. Currently this issue persists in 0.16.4 and 0.17.1 versions.
A simple example. ---- mystate.sls--- /tmp/test-file1: file.touch
/tmp/test-file1: file.managed: - source: salt://another-file2 ------mystate,sls----
I can run salt '*' state.sls mystate and it will execute one of the state from above.
I confirm it's not throwing an error when the same ID is referenced twice (or more) within a state.
It detects the conflict when the ID is in different states though : The conflicting ID is "cli-packages" and is found in SLS "common:sshd" and SLS "common:packages.cli"
@sebw The conflicting IDs for included states should be fixed.
The lack of conflicting ID errors in a single state file is a regression that we will get fixed.
Can anyone verify that this one is fixed so we can close it?
The original issue contains the following sample SLS which was said to incorrectly execute at least one of the states:
/tmp/test-file1:
file.touch
/tmp/test-file1:
file.managed:
- source: salt://another-file2
As of today's develop branch running salt-call --local state.sls <test_sls.sls> returns:
local:
Data failed to compile:
----------
Rendering SLS "base:mystate" failed: Conflicting ID "/tmp/test-file1"
This is expected behavior. Therefore, I am closing this issue. If it needs to stay open for some reason, please leave a comment and we'll re-open. Thanks!
Great!
@ cachedout That is the expected behavior? Is there a way to work around this? (Yes, Emilisto, I just posted this question on your other post) =). I need to touch/append a single file multiple times and am running to this error. Looking forward to the reply.
@KatoneVi The common approach is to use the name argument to file.managed to target a particular file in multiple state declarations and to make the IDs of those declarations unique.
Here's an example:
my_id_1:
file.managed:
- name: /tmp/foo
<snip other args>
my_id_2:
file.managed:
- name: /tmp/foo
<snip different args than my_id_1, assumably>
Thanks a bunch =) It worked!!!! ^_^