salt icon indicating copy to clipboard operation
salt copied to clipboard

requiring sls file containing only includes fail

Open kintel opened this issue 12 years ago • 31 comments

I have the following file structure:

includetest/init.sls
includetest/subtestfile.sls
includetest/testfile.sls

init.sls:

include:
  - includetest.testfile

/home/deploy/testfile2.txt:
  file.managed:
    - contents: Hello
    - require:
      - sls: includetest.testfile

testfile.sls:

include:
  - .subtestfile

subtestfile.sls:

/home/deploy/subtestfile.txt:
  file.managed:
    - contents: Hello

When running salt-call state.sls includetest, I get:

    State: - file
    Name:      /home/deploy/testfile2.txt
    Function:  managed
        Result:    False
        Comment:   The following requisites were not found:
                   require:
                       sls: includetest.testfile

Playing around a bit, it appears that this is caused by requiring a file containing only includes. A workaround is to modify testfile.sls to do some arbitrary work.

Is this a bug or by design? My use-case is to have a file including a bunch of states and requiring that file from various places. (Tested on 0.17.5)

kintel avatar Feb 28 '14 05:02 kintel

Likely just an edge-case that we're not handling. Thanks for the report, we'll investigate.

basepi avatar Feb 28 '14 20:02 basepi

I'm speculating that this is due to the require system looking for states in the lowstate that have an __sls__ value that matches the include. Since an sls file that only includes won't create any states that have that value it fails.

whiteinge avatar Apr 11 '14 21:04 whiteinge

@kintel A quick workaround would be to make a "dummy" state in the sls which requires those includes:

include:
  - .subtestfile

dummy_testfile_include:
  module:
    - wait
    - name: test.ping
    - require:
      - sls: subtestfile

whiteinge avatar Apr 11 '14 21:04 whiteinge

@whiteinge Thanks - I'm using the dummy strategy already. Note that your example only works on the top level due to #10838

kintel avatar Apr 11 '14 22:04 kintel

I ran into this bug as well. We have a "common" sls group that includes all the different sections:


include:
  - common.users
  - common.packages
  - common.services
  - common.tools

I've done the work-around that @whiteinge suggested, but it would be nice not having to have a dummy state.

JustinCarmony avatar May 05 '14 17:05 JustinCarmony

@whiteinge and @kintel thanks for suggesting an alternative solution. This was much needed.

spareslant avatar Feb 11 '15 22:02 spareslant

Just wasted ~3h on this bug too until I realized what I was dealing with :) Using now a simple test.configurable_test_state as workaround which could also be replaced with test.nop (available since 2015.5.6) - depending on the used Salt version.

eliasp avatar Sep 24 '15 12:09 eliasp

@eliasp Join the club. :) It's generally not obvious what the problem is when you hit it. This drove me nuts last year until it was burned into my mind to always watch out for this.

I'm very glad to see this bumped up from Low to High severity at least.

boltronics avatar Sep 24 '15 13:09 boltronics

It appears for understandable reasons there is same behavior when you include an 'empty' file, say for example you include a file wrapped in conditionals that don't trigger. So more appropriately this bug triggers when you simply include an sls without any states.

JaseFace avatar Sep 23 '16 20:09 JaseFace

shame this hasn't been fixed even after 3 y (spent ages to find why i got this issue)

DanyC97 avatar Feb 03 '17 13:02 DanyC97

I also recently ran into this, and it took quite awhile to find this issue and the underlying reason it's failing. Has there been any movement on this? Or at the very least, could the documentation be updated to point out that requiring an empty sls, or an sls that only has include statements, currently fails?

sean-bennett112 avatar Feb 24 '17 20:02 sean-bennett112

This isn't currently being worked on. Two ideas that have been floated is to have Salt's YAML parser automatically add a test.nop state to empty files or to figure out a change to Salt's state compiler that can detect this condition another way.

In the meantime, a docs addition is a great idea. This doc is a good first place to add a warning. @sean-bennett112 are you interested in adding that? You can edit that file directly from GitHub's web UI if you'd like.

whiteinge avatar Feb 24 '17 23:02 whiteinge

@whiteinge sorry for the late reply. I'd be happy to add a warning to the docs. However, is that the best place to add one? I'd think a better location would be here, given that page tends to be the first or second result in Google when I'm trying to debug a requisites issue.

sean-bennett112 avatar Feb 27 '17 19:02 sean-bennett112

@sean-bennett112 good call! A warning in both wouldn't be too much, IMO.

whiteinge avatar Feb 27 '17 23:02 whiteinge

Belated happy 3rd birthday to this bug ;) Is there sometimes a fix to be in sight? Since on other usages this multilevel references are unproblematic (pillar, grains, sls references for includes) it shouldn't be too problematic / difficult to get here also a solution?

The above mentioned workaround could /has to be used then but I was just trying to avoid single state reference and use a whole sls as required_in because saltstack likes to play dice with state ordering already also in the referenced sls

Reiner030 avatar Apr 20 '17 08:04 Reiner030

Just hit the nail with this bug now. I guess that's the price to pay for trying to write organized formulas. :(

ghost avatar Nov 30 '17 15:11 ghost

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

stale[bot] avatar Mar 25 '19 16:03 stale[bot]

I think it is still an issue

kiemlicz avatar Mar 26 '19 09:03 kiemlicz

Thank you for updating this issue. It is no longer marked as stale.

stale[bot] avatar Mar 26 '19 09:03 stale[bot]

update on this?

MalloZup avatar Jul 26 '19 08:07 MalloZup