如果存在特定文件就不执行,例如不存在/etc/nginx目录就安装nginx:
nginx:
pkg:
- name: nginx
- installed
- unless: test -d /etc/nginx
只有存在特定文件才执行,如存在/etc/init.d/httpd就删除httpd:
httpd:
pkg:
- name: httpd
- removed
- onlyif: test -f /etc/init.d/httpd
发布时间:April 2, 2015 // 分类:Puppet // No Comments
如果存在特定文件就不执行,例如不存在/etc/nginx目录就安装nginx:
nginx:
pkg:
- name: nginx
- installed
- unless: test -d /etc/nginx
只有存在特定文件才执行,如存在/etc/init.d/httpd就删除httpd:
httpd:
pkg:
- name: httpd
- removed
- onlyif: test -f /etc/init.d/httpd
发布时间:May 18, 2014 // 分类:Puppet // No Comments
执行命令时直接分组:
#匹配slave id前缀为vps的所有slave
salt -C 'vps*' test.ping
配置文件分组:
nodegroups:
vps: 'vps*'
执行:
salt -N vps test.ping
更多匹配操作:
http://docs.saltstack.com/en/latest/topics/targeting/compound.html
发布时间:January 27, 2014 // 分类:Puppet // No Comments
配置仓库根目录:
file_roots:
base:
- /srv/salt
创建入口文件:
cat > /srv/salt/top.sls << EOF
base:
'*': #匹配所有受控主机
- nginx
EOF
创建nginx sls:
mkdir -p /srv/salt/nginx
cat > /srv/salt/nginx/init.sls << EOF
nginx:
pkg:
- name: nginx
- installed
service:
- running
- enable: True
- reload: True
- require:
- pkg: nginx
- pkg: httpd
- watch:
- pkg: nginx
- file: /etc/nginx/nginx.conf
- file: /etc/nginx/conf.d/
httpd:
pkg:
- name: httpd
- removed
/etc/nginx/nginx.conf:
file.managed:
- source: salt://nginx/nginx.conf
- user: root
- group: root
- mode: 644
/etc/nginx/conf.d/:
file.recurse:
- source: salt://nginx/conf.d/
- user: root
- group: root
- dir_mode: 755
- file_mode: 644
/home/wwwlogs/:
file.directory:
- makedirs: True
- user: nginx
- group: nginx
- mode: 0755
- recurse:
- user
- group
- mode
EOF
执行:
salt '*' state.highstate
或
salt '*' state.sls nginx
发布时间:January 27, 2014 // 分类:Puppet // No Comments
cat > /etc/salt/roster << EOF
test:
host: 192.168.1.1
user: root
password: redhat
EOF
通过salt-ssh执行,第一次执行后会添加auth key
salt-ssh '*' cmd.run "uptime"
发布时间:January 27, 2014 // 分类:Puppet // No Comments
Master:
curl -L http://bootstrap.saltstack.org | sudo sh -s -- -M -N
yum search salt-ssh
Slave:
wget -O - http://bootstrap.saltstack.org | sudo sh
yum install salt-minion
客户端配置:
Master: 192.168.1.1
#识别ID
id: test
启动客户端:
/etc/init.d/salt-minion start
服务器端确认:
salt-key -A
执行模块命令:
salt '*' test.ping
执行shell命令:
salt '*' cmd.run "uptime"
执行脚本命令:
mkdir -p /srv/salt/scripts/
cat > /srv/salt/scripts/test.sh << EOF
#!/bin/bash
echo "test" > /tmp/test.txt
echo $1
echo $2
echo $3
EOF
salt '*' cmd.script salt://scripts/test.sh "aa bb cc"
同步服务器状态,安装git:
cat >/srv/salt/git.sls << EOF
git:
pkg:
- installed
EOF
salt '*' state.sls git
查看节点信息:
salt '*' grains.ls 查看grains分类
salt '*' grains.items 查看grains所有信息
salt '*' grains.item osrelease 查看grains某个信息