I am trying to learn Salt. Proving to be cumbersome. Can't even get around master config. What is wrong with the below line?
#/etc/salt/master
file_roots:
base:
- /home/ubuntu/workspace/salt/states/base
salt-key -L
[ERROR ] Error parsing configuration file: /etc/salt/master - expected '<document start>', but found '<block mapping start>'
in "<string>", line 298, column 1:
file_roots:
^
##### File Server settings #####
##########################################
# Salt runs a lightweight file server written in zeromq to deliver files to
# minions. This file server is built into the master daemon and does not
# require a dedicated port.
# The file server works on environments passed to the master, each environment
# can have multiple root directories, the subdirectories in the multiple file
# roots cannot match, otherwise the downloaded files will not be able to be
# reliably ensured. A base environment is required to house the top file.
# Example:
file_roots:
base:
- /home/ubuntu/workspace/salt/states/base
# development:
# - /home/ubuntu/workspace/salt/states/dev
# dev:
# - /srv/salt/dev/services
# - /srv/salt/dev/states
# prod:
# - /srv/salt/prod/services
# - /srv/salt/prod/states
#file_roots:
# base:
# - /srv/salt
Here's the problem:
In YAML, spacing and indentation is really important. You should have two spaces for each level. While you have 2 spaces for base:, you should have 4 spaces before
- /home/ubuntu/workspace/salt/states/base
Here's the correct one:
file_roots:
base:
- /home/ubuntu/workspace/salt/states/base
Without seeing more of the relevant section of your /etc/salt/master it's difficult to give you the exact answer to your problem, but you're seeing a malformed yaml error. Your file_roots section should look similar to this:
file_roots:
base:
- /srv/salt
There's more info here:
http://docs.saltstack.com/en/latest/ref/file_server/file_roots.html#directory-overlay
Also, it's possible that there's an error above the yaml you're displaying.
If you'll post more of your config (sanitized of course) we can better help you.
Related
I am trying to install and set-up some basic saltstack states.
I am getting the following error when trying to apply a state:
No matching sls found for 'httpd' in env 'base'
My setup is as follows:
Centos 7.7.1908
Salt 3000
My directory structure is:
/etc/salt/srv/salt/httpd.sls
And my file contains:
install_httpd:
pkg.installed:
- httpd
The command I am running is:
salt minion state.sls httpd
I have also tried created a top.sls file under:
/etc/salt/srv/pillar/top.sls
And this file contains:
base:
'*':
- httpd
But I get the same error. However, as far as I am aware, a top.sls file should not be necessary.
Does anyone have any suggestions on this?
Cheers
So, I found the answer to my own question.
I was assuming that /srv/salt/ should exist within /etc/salt/, which was incorrect. /srv/salt/ should be its own directory. So if I run pwd while inside /srv/salt/ it looks like this:
/srv/salt
If you want to change this so that /srv/salt can sit within /etc/salt/ you will need to adjust your file_roots on line 667 of /etc/salt/master to be:
file_roots:
base:
- /etc/salt/srv/salt
I want to use relative paths when including sls files. This approach works when including state files but does not work when including pillar files.
Let's assume I have the following structure on my salt master:
file_roots:
base:
- /srv/salt/states
pillar_roots:
base:
- /srv/salt/pillars
And let's assume I have the following files:
/srv/salt/states/top.sls
/srv/salt/states/test/
/srv/salt/states/test/init.sls
/srv/salt/states/test/test_state.sls
In the top.sls file I include the test directory like this:
base:
'*':
- test
The init.sls file then includes the actual state file like this:
include:
- .test_state
When I call the highstate everything works as expected. Now I use the same logic for pillar data. That means I have the following files:
/srv/salt/pillars/top.sls
/srv/salt/pillars/test/
/srv/salt/pillars/test/init.sls
/srv/salt/pillars/test/test_pillar.sls
In the test_pillar.sls file I put one pillar like this:
test_pillar: text
The init.sls file looks like this (analogue to the init.sls file above):
include:
- .test_pillar
When I call the highstate now I get the following error message:
Data failed to compile:
----------
Pillar failed to render with the following messages:
----------
Specified SLS '.test_pillar' in environment 'base' is not available on the salt master
So I go back to the init.sls file and make the file path absolute:
include:
- test.test_pillar
Now it works.
To make a long story short: salt allows me to use relative paths in the init.sls for the state files but complains when doing the same for the pillar data.
Is this the intended behaviour? Or do I have to use some other syntax maybe?
Relative includes for pillar files was added with this commit: https://github.com/saltstack/salt/pull/52156
But as of this writing, 15 Nov 2019, it doesn't look like it has made it into a release yet.
All of our salt scripts are located in /srv/salt/ and /srv/pillar/ directories and they are synced with SVN.
In salt configuration file (/etc/salt/master) I have defined the file_roots and pillar_roots as below so once any salt command is executed, it uses these paths.
file_roots:
base:
- /srv/salt/
pillar_roots:
base:
- /srv/pillar/
I want to create a new directory and duplicate all the scripts there (/srv/salt_test/salt/ and /srv/salt_test/pillar/) for test.
Is there any way that I can pass parameters to salt command to force it to use these test path? Something like:
$salt file_roots=/srv/salt_test/salt/ pillar_roots=/srv/salt_test/pillar/ servername.domain.com state.sls weblogic.install
Thanks a lot in advance.
I found the solution and would like to share it here:
I've updated /etc/salt/master as below:
file_roots:
base:
- /srv/salt/
test:
- /srv/salt_test/
pillar_roots:
base:
- /srv/pillar/
test:
- /srv/pillar_test/
Then restarted salt on master and minions. Now I can use saltEnv=test pillarEnv=test options to force salt master to read scripts from /srv/pillar_test/ and /srv/salt_test/
Sample:
$salt minion.domain.com state.sls weblogic.install saltEnv=test pillarEnv=test
Hope it will be useful for someone else.
In my /etc/salt/master I have the following options set:
file_roots:
base:
- /srv/salt
dev:
- /srv/salt/dev
AND
top_file_merging_strategy: same
default_top: base
I have a top.sls for base(/srv/salt/top.sls) environment, which goes:
base:
'*':
- files
Where files.sls in defined in /srv/salt
And one top.sls for dev(/srv/salt/dev/top.sls) environment, which goes:
dev:
'saltMinion1':
- django
'saltMinion2':
- MySQL
Where django.sls and MySQL.sls are defined in /srv/salt/dev/.
Now if I call:
salt '*' state.highstate
When I am using top_file_merging_strategy: merge, then both base and dev environment are getting applied to my minions, whereas for this scenario, I am using top_file_merging_strategy: same, ONLY base environment is getting applied. But according to Salt documentation: Top File, both base as well as dev environments should have gotten applied.
What am I doing wrong? Any help is appreciated.
I think you are experiencing this. It's been fixed in Salt 2016.11.
I'm trying to use Salt to deploy an online tool to a new VPS. The process involves cloning a git repo and then various set-up commands - however there seems to be an issue with including other .sls files from within sub directories.
Here's a simplified version:
Master config file:
file_roots:
base:
- /srv/salt/saltstates
I have a a file in /srv/salt/saltstates/test/test.sls containing:
base:
'*':
- basic
The file /srv/salt/saltstates/test/basic.sls contains:
Europe/London:
timezone.system
However, when I run salt 'Minion1' state.sls test.test, an error is returned:
Minion1:
----------
ID: base
Function: *.basic
Result: False
Comment: State *.basic found in sls test.test is unavailable
Started:
Duration:
Changes:
OK, so you've confused several things here.
First of all the contents you've put in /srv/salt/saltstates/test/test.sls really is what is called a top file and should probably be moved to /srv/salt/saltstates/top.sls
The top.sls is only needed if you want to do a highstate, but since you're trying to run salt 'Minion1' state.sls test.test you don't really need the top.sls.
Now since you have your sls file here: /srv/salt/saltstates/test/basic.sls, then the command you want to run is the following:
salt 'Minion1' state.sls test.basic
The "dot" traverses down directories.