salt-stack

How to compare version strings in salt sls files

穿精又带淫゛_ 提交于 2019-12-05 21:33:12
Does saltstack have an equivalent to puppets versioncmp() function? Or alternatively, is there a way to get the distutils.version or packaging.version.parse methods (as mentioned on Compare version strings in Python ) available in a jinja+yaml rendered sls file? you can use the module pkg.version_cmp : # salt-call pkg.version_cmp '1.0.2' '1.1.1' local: -1 # salt-call pkg.version_cmp '0.2.4.1-0ubuntu1' '0.2.4-0ubuntu1' local: 1 Inside jinja you can use it in a way similar to: {% if salt['pkg.version_cmp']('1.1.0','1.0.5') > 0 %} .... {% endif %} 来源: https://stackoverflow.com/questions/45701907

salt-stack highstate - find slow states

跟風遠走 提交于 2019-12-05 08:52:51
Running an initial install takes about 20 minutes, running a salt-call state.highstate takes about 6 minutes. That's not unreasonable, but I'd like to speed it up, but I'm not sure how to find the slowest states. Is there any way to find how long each state takes to run other than watching my screen with a stopwatch for 6 minutes? sudo salt-call state.highstate provides start-time and duration for each state. ---------- ID: ntp-removed Function: pkg.removed Result: True Comment: None of the targeted packages are installed Started: 12:45:04.430901 Duration: 0.955 ms Changes: You can capture

Are conditionals in salt stack pillar templates secure?

老子叫甜甜 提交于 2019-12-05 07:10:43
I recently saw the following construction in a salt pillar in a thread here /srv/pillar/ssh.sls : ssh_certs: {% if grains['fqdn'] == 'server1.example.com' %} dsa: | -----BEGIN DSA PRIVATE KEY----- {# key text goes here with consistant indentation... #} -----END DSA PRIVATE KEY----- ecdsa: | -----BEGIN ECDSA PRIVATE KEY----- {# key text goes here with consistant indentation... #} -----END ECDSA PRIVATE KEY----- rsa: | -----BEGIN RSA PRIVATE KEY----- {# key text goes here with consistant indentation... #} -----END RSA PRIVATE KEY----- {% elif grains['fqdn'] == 'server2.example.com' %} # same as

(SaltStack) ID dog in SLS dog is not a dictionary

巧了我就是萌 提交于 2019-12-05 04:34:31
I have been trying to find a pattern (bcm2708_wdog) in the /etc/modules file and if it isnt there add it to the bottom. Every time I try this I get the "ID dog in SLS dog is not a dictionary". I have no idea what this means. Here is the file: dog: - file.replace: - name: /etc/modules - pattern: 'bcm2708_wdog' - append_if_not_found: True It should probably look like this: dog: file.replace: # <--------this line was your problem. - name: /etc/modules - pattern: 'bcm2708_wdog' - append_if_not_found: True Lines beginning with "-" denote items in a list. In your version, you've defined the top

How can I execute multiple commands using Salt Stack?

跟風遠走 提交于 2019-12-04 07:48:07
问题 I tried to add: mypack: pkg: - installed - pkgs: - mercurial - git cmd.run: - name: 'mkdir -p /opt/mypack' cmd.run: 'hg pull -u -R /opt/mypack || hg clone -R /opt https://...' cmd.run: 'ln -s /opt/mypack/etc/init.d/xxx /etc/init.d/xxx' But for some reason this the state seems to execute/install but the commands are not executed, or at least not all of them. I need a solution to run multiple commands and to fail the deployment if any of these fails. I know that I could write a bash script and

how to render and dump the file sls with salt stack without applying it

限于喜欢 提交于 2019-12-03 12:24:30
Given how flexible jinja templating can be with saltstack and the numerous pillar variables are merged into the template; I would find it useful to be able to get salt to 'render' the full sls out to screen before i push it out. Is there a way of doing this? yee379 Just to answer my own question: I knew that state.show_top existed. So I tried state.show_sls , and voila! Exactly what I'm after. 来源: https://stackoverflow.com/questions/34191710/how-to-render-and-dump-the-file-sls-with-salt-stack-without-applying-it

salt stack: grains vs pillars

只愿长相守 提交于 2019-12-03 08:14:27
问题 In the Salt system there are grains and pillars. I understand how I can assign custom grains, but when would it be better to consider using pillars? 回答1: The fundamental difference here is that you can set a custom grain as an innate property of a minion, versus pillar which needs to be assigned to a minion at some point. For example, there are two practical ways to assign a role to a minion: the minion id or using custom grains. You can then match against the minion id or custom grains

Salt Stack: using execution modules in SLS

我只是一个虾纸丫 提交于 2019-12-03 06:30:43
问题 So far as I can see in the Salt documentation (e.g. here) there are two main types of modules supported: state modules and execution modules (I know there're also renderers, returners and so on). Most of examples of SLS files contain statements related only to state modules (under salt.state namespace) whereas for execution modules only command line examples are shown. For example we have two modules named "service": salt.states.service and salt.modules.service. Right now I have problems

Check file exists and create a symlink

你。 提交于 2019-12-03 03:23:11
I want to do something like that: if file A exists or there is no symlink B, I want to create a symlink B -> A. For now I have: B: file: - symlink: - target: A - exists: - name: A But this is bad it checks not the thing I want. How can I achive this simple thing in salt ? We can use file.directory_exists {% if not salt['file.directory_exists' ]('/symlink/path/A') %} symlink: file.symlink: - name: /path/to/A - target: /symlink/path/A {% endif %} Jason Zhu You should use Dan Garthwaite 's excellent answer here as a basis for how to check for the existence of a file. I have modified his solution

Calling one Bash script from another Script passing it arguments with quotes and spaces

时光怂恿深爱的人放手 提交于 2019-12-03 02:36:41
问题 I made two test bash scripts on Linux to make the problem clear. TestScript1 looks like: echo "TestScript1 Arguments:" echo "$1" echo "$2" echo "$#" ./testscript2 $1 $2 TestScript2 looks like: echo "TestScript2 Arguments received from TestScript1:" echo "$1" echo "$2" echo "$#" When i execute testscript1 in the following way: ./testscript1 "Firstname Lastname" testmail@domain.com The desired Output should be: TestScript1 Arguments: Firstname Lastname testmail@domain.com 2 TestScript2