Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

salt states duplicate key detection #8053

Closed
mlister2006 opened this issue Oct 23, 2013 · 8 comments
Closed

salt states duplicate key detection #8053

mlister2006 opened this issue Oct 23, 2013 · 8 comments
Labels
Bug broken, incorrect, or confusing behavior Regression The issue is a bug that breaks functionality known to work in previous releases. severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around

Comments

@mlister2006
Copy link
Contributor

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.

@sebw
Copy link
Contributor

sebw commented Oct 23, 2013

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"

@basepi
Copy link
Contributor

basepi commented Oct 23, 2013

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

emilisto added a commit to emilisto/salt that referenced this issue Nov 16, 2013
- YAML exceptions are now re-reaised as SaltRenderErrors
- Duplicate ID's in single state files now result in errors, and not
  just warnings. This is now consistent with the how conflicting ID's in
  separate state files are handled.
terminalmage pushed a commit that referenced this issue Nov 17, 2013
Fix for issue #8053: raise error on duplicate ID's in one state file
@basepi
Copy link
Contributor

basepi commented Nov 19, 2013

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

basepi pushed a commit that referenced this issue Nov 20, 2013
- YAML exceptions are now re-reaised as SaltRenderErrors
- Duplicate ID's in single state files now result in errors, and not
  just warnings. This is now consistent with the how conflicting ID's in
  separate state files are handled.
@cachedout
Copy link
Contributor

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!

@emilisto
Copy link
Contributor

Great!

@KatoneVi
Copy link

KatoneVi commented Feb 7, 2014

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

@cachedout
Copy link
Contributor

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

@KatoneVi
Copy link

KatoneVi commented Feb 7, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug broken, incorrect, or confusing behavior Regression The issue is a bug that breaks functionality known to work in previous releases. severity-medium 3rd level, incorrect or bad functionality, confusing and lacks a work around
Projects
None yet
Development

No branches or pull requests

6 participants