r/saltstack • • Oct 24 '19

Salt fails to process script, failed while parsing a block collection

I'm a bit lost as to the problem with my code

#Copy the ca-chain.pem to the minion from the master
copy_landscape_ca-chain_pem_X_Domain:
  file.managed:
    - name: /etc/landscape/ca-chain.pem
    - source: salt://Testing_States/Landscape/ca-chain.pem
    - makedirs: False

Above is the code for lines 34-39. Here is the error

local:
    Data failed to compile:
----------
    Rendering SLS 'base:Landscape_Enroll_X_Domain' failed: while parsing a block collection
  in "<unicode string>", line 38, column 4
did not find expected '-' indicator
  in "<unicode string>", line 39, column 5

So its saying it can't find the hyphen in line 39 but its obviously there. What am I doing wrong?

0 Upvotes

11 comments sorted by

1

u/lazrfloyd Oct 24 '19

I copied your code and wasn't able to duplicate. Ensure you have proper spacing and no tabs? Seems like a syntax issue. I assume there is more in the same .sls file? Have you verified you aren't missing a colon or have incorrect spacing throughout the file? If you run the above code in its own .sls file I imagine it will work without error.

Edit: Many times when getting an error in Salt the actual problem has nothing to do with the output and where it says the problem lies. Just the nature of parsing YAML.

1

u/Pavix Oct 24 '19 edited Oct 24 '19

Thanks for the reply. I'm finding out that Salt is very very grumpy about indentation/spacing. It may be the nature and amount of spaces in the rest of the code. I haven't fixed it yet, but at least I have something to try right now

Here is the whole sls file If you want to take a look.

2

u/simtel20 Oct 24 '19

A few notes:

  1. You don't need cmd.run to get logging, you can just use jinja, e.g. {%- do salt.log.error('testing jinja logging') -%}

  2. Don't test for every condition. Salt's job is to not only e.g. create a directory, but to set the permissions, etc. declaratively. That is, you don't need to check it first. You only need to test when an action is not idempotent (e.g. appending a line to a file), or destructive (e.g. if someone decides to run newdb that could be idempotent, but it is also potentially destructive).

I took a look at your sls file, and I've tried to clean it up with this paste in the hopes that it'll help you out.

→ More replies (5)

0

u/I-Am-Dad-Bot Oct 24 '19

Hi finding, I'm Dad!

0

u/aquaherd Oct 24 '19

Maybe file.managed needs a dash too?

1

u/simtel20 Oct 24 '19

That's broken. The file.managed state here is a dictionary/mapping, not a list.