salt-stack

salt stack: grains vs pillars

拟墨画扇 提交于 2019-12-02 21:51:59
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? akoumjian 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 inside your top.sls file like so: # salt/top.sls base: # match against custom grain 'G@role:webserver':

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

爷,独闯天下 提交于 2019-12-02 17:25:44
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 Arguments received from TestScript1: Firstname Lastname testmail@domain.com 2 But the actual output is:

expect script works while invoking individually but not as a salt state

强颜欢笑 提交于 2019-12-02 08:33:25
I'm trying to do scp as well as ssh through expect. Below script works if I invoke it directly from terminal like /usr/bin/expect myexpect.sh but when I ran it using salt, the first scp command works where the second ssh fails. myexpect.sh #!/usr/bin/expect -f set timeout 240 spawn scp apps.tar.gz /srv/salt/integration/serverclass_merged.conf foo@10.10.10.10:/home/foo expect "password:" send "password\n"; expect eof spawn ssh -o StrictHostKeyChecking=no foo@10.10.10.10 "cd /home/foo;tar --strip-components=1 -xzvf apps.tar.gz -C /opt/apps/;cp serverclass_merged.conf /opt/local/serverclass.conf"

what's the big difference between execution modules and state modules

≯℡__Kan透↙ 提交于 2019-12-01 05:51:57
Recently, I'm learning salt from its doc. However, I'm quite confused about execution modules and state modules. Why there are two types of module? Why they can't unify? If we have just one type of module that can be used both on command line and in sls file, isn't it simpler and better? In short: Execution modules: execute a task States module: try to get to a certain state/configuration. Execution modules: They are designed to perform tasks on a minion. For example: mysql.query will query a specified database. The execution module does not check if the database needs to be queried or not. It

what's the big difference between execution modules and state modules

。_饼干妹妹 提交于 2019-12-01 03:08:36
问题 Recently, I'm learning salt from its doc. However, I'm quite confused about execution modules and state modules. Why there are two types of module? Why they can't unify? If we have just one type of module that can be used both on command line and in sls file, isn't it simpler and better? 回答1: In short: Execution modules: execute a task States module: try to get to a certain state/configuration. Execution modules: They are designed to perform tasks on a minion. For example: mysql.query will

Defining states depending on existance of a file/directory

自作多情 提交于 2019-11-30 22:24:35
How is it possible to get something like the following running: {% if not exist('/tmp/dummy/') then %} dummy: file.touch: - name: /tmp/dummy/tmp.txt ... {% endif %} I need it for installing software from a ZIP-file. I want to unzip on the minions, but there I don't want to have any remnants of licence files, which I only need for installation, left. You can use unless for this. dummy: file.touch: - name: /tmp/dummy/tmp.txt - unless: test -d /tmp/dummy/ {% if 1 == salt['cmd.retcode']('test -f /tmp/woo.test') %} ack: file.touch: - name: /tmp/woo.test {% endif %} You could use the pure python

Defining states depending on existance of a file/directory

拜拜、爱过 提交于 2019-11-30 17:48:10
问题 How is it possible to get something like the following running: {% if not exist('/tmp/dummy/') then %} dummy: file.touch: - name: /tmp/dummy/tmp.txt ... {% endif %} I need it for installing software from a ZIP-file. I want to unzip on the minions, but there I don't want to have any remnants of licence files, which I only need for installation, left. 回答1: You can use unless for this. dummy: file.touch: - name: /tmp/dummy/tmp.txt - unless: test -d /tmp/dummy/ 回答2: {% if 1 == salt['cmd.retcode']

How to get a list of all salt minions in a template?

牧云@^-^@ 提交于 2019-11-30 01:15:59
Basically I am creating a Salt state describing Munin server configuration and I need to get a list of all minions known to the master, something like this: {% for host in pillar['munin_clients'] %} [{{ host.fqdn }}] address {{ host.ip }} use_node_name yes {% endfor %} The only difference is that I don't want to use pillar for that, I need this list to be populated dynamically. ret.get_minions seems to be relevant but I can't make it work for some reason. What are my options? I managed to achieve this using Salt Mine system (thanks to members of Salt-users Google group): {% for host, hostinfo

How to get a list of all salt minions in a template?

蹲街弑〆低调 提交于 2019-11-28 22:15:37
问题 Basically I am creating a Salt state describing Munin server configuration and I need to get a list of all minions known to the master, something like this: {% for host in pillar['munin_clients'] %} [{{ host.fqdn }}] address {{ host.ip }} use_node_name yes {% endfor %} The only difference is that I don't want to use pillar for that, I need this list to be populated dynamically. ret.get_minions seems to be relevant but I can't make it work for some reason. What are my options? 回答1: I managed