salt icon indicating copy to clipboard operation
salt copied to clipboard

salt states duplicate key detection

Open mlister2006 opened this issue 13 years ago • 8 comments

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.

mlister2006 avatar Oct 23 '13 16:10 mlister2006

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 avatar Oct 23 '13 20:10 sebw

@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.

basepi avatar Oct 23 '13 21:10 basepi

Can anyone verify that this one is fixed so we can close it?

basepi avatar Nov 19 '13 23:11 basepi

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!

cachedout avatar Dec 28 '13 18:12 cachedout

Great!

emilisto avatar Dec 28 '13 19:12 emilisto

@ 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.

WeLoveJesusChrist avatar Feb 07 '14 17:02 WeLoveJesusChrist

@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>

cachedout avatar Feb 07 '14 18:02 cachedout

Thanks a bunch =) It worked!!!! ^_^

WeLoveJesusChrist avatar Feb 07 '14 19:02 WeLoveJesusChrist