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.
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.
I'm trying to create a win repo within my isolated environment.
At the /etc/salt/master I added the lines:
winrepo_dir_ng: repo
winrepo_insecure_auth: True
winrepo_cachefile: winrepo.p
On the minion configuration file (a windows minion):
winrepo: salt-master://win/repo
winrepo_cachefile: 'c:/salt/repo/cache'
Of course after that I used the following commands:
salt-run winrepo.genrepo
returns the sls content
salt '*' pkg.refresh_db
returns empty line (should be 'true').
When I try "salt '*' pkg.install notepad" it returns "unable to locate package notepad".
Where am I wrong?
comment out all those lines you've configured in your master and minion configs. The defaults should all work fine.
I'm new to Saltstack and I'm just trying to do some simple installs on a subset of minions. I want to include Environments so I have my file roots as:
file_roots:
base:
- /srv/salt/base
dev:
- /srv/salt/dev
qa:
- /srv/salt/qa
stage:
- /srv/salt/stage
prod:
- /srv/salt/prod
I set up the git backend:
fileserver_backend:
- git
- roots
I'm using gitfs set as:
gitfs_remotes:
- https://github.com/saltstack-formulas/postgres-formula
- https://github.com/saltstack-formulas/apache-formula
- https://github.com/saltstack-formulas/memcached-formula
- https://github.com/saltstack-formulas/redis-formula
So I have the master set up and I add top.sls to /srv/salt/stage with
include:
- apache
stage:
'stage01*':
- apache
But I get an error when I execute
salt -l debug \* state.highstate test=True
Error
stage01.example.net:
Data failed to compile:
----------
No matching sls found for 'apache' in env 'stage'
I've tried many ways and the master just can't seem to find the apache formula I configured for it.
I found the answer and it was sitting in the Saltstack docs the whole time.
First you will need to fork the current repository such as postgres-formula.
Depending on the environment create a branch of the same name in your newly create fork of the repo.
So for example I wanted to use postgres in my stage environment. So it wouldn't work until I created a branch named stage ined my forked repo of postgres-formula then it worked like a charm.