salt自定义变量传参执行sls

以下使用安装redis为例子,动态传密码:

一、redis_install.sls

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
redis-conf:
cmd.run:
- name: mkdir -p /data/redis6379/{data,logs} && chown redis.redis -R /data/redis6379/ && echo "su - redis -c '/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis6379.conf &'" >> /etc/rc.local
- require:
- cmd: redis-install
{% set redis_pass = salt['pillar.get']('redis_pass','xxxxx') %}
file.recurse:
- name: /usr/local/redis/conf
- source: salt://Redis/file/conf
- user: redis
- group: redis
- dir_mode: 731
- template: jinja
- defaults:
redis_pass: {{ redis_pass }} ==>注意使用4个空格
- require:
- cmd: redis-install

二、file/conf/redis6379.conf

1
requirepass {{ redis_pass }}

三、执行命令

1
salt-ssh '192.168.162.113' state.sls Redis.redis_install  pillar='{"redis_pass":"redis"}'

Comments

2017-08-27