salt-ssh
1. 安装: yum install salt-ssh
2. vim /etc/salt/roster
xiaozhu:
host: 192.168.4.32 注意两个空格
user: root
passwd: 123456
port: 22
timeout: 10
3. 使用
alt-ssh 'dianlan' -r 'uptime' -i
注-r 使用shell , -i 忽略(yes/no)的提示消息,第二次则不必使用
关于参数:
-r, �Craw, �Craw-shell # 直接使用shell命令
�Cpriv #指定SSH私有密钥文件
�Croster #指定roster类型
�Croster-file #指定roster文件
�Crefresh, �Crefresh-cache #刷新cache
�Cmax-procs #指定进程数,默认为25
-i, �Cignore-host-keys #当ssh连接时,忽略keys
�Cpasswd #指定默认密码
�Ckey-deploy #配置keys
salt-ssh ‘test85′ �Ckey-deploy test.ping
当调用master模块时,并加上参数 �Ckey-deploy 即可在minions生成keys,下次开始就不使用密码
4. salt-ssh安装minion(centos6)
[root@qing salt]# tree minion/
minion/
├── epel.sls
├── files
│ ├── epel-release-6-8.noarch.rpm
│ ├── epel.repo
│ └── minion
├── init.sls
└── install.sls
1 directory, 6 files
[root@qing salt]#
[root@qing salt]# cat minion/epel.sls
epel_delear:
file.managed:
# - source: salt://minion/files/epel-release-6-8.noarch.rpm
# - name: /tmp/epel-release-6-8.noarch.rpm
# - mode: 755
- source: salt://minion/files/epel.repo
- name: /etc/yum.repos.d/epel.repo
- unless: test -e /etc/yum.repos.d/epel.repo
epel_install:
cmd.run:
- name: rpm -ivh /tmp/epel-release-6-8.noarch.rpm
- unless: test -e /etc/yum.repos.d/epel.repo
- require:
- file: epel_delear
[root@qing salt]# cat minion/install.sls
minion_install:
pkg.installed:
- pkgs:
- salt-minion
- salt
minion_service:
service.running:
- name: salt-minion
- enable: True
- reload: True
- watch:
- file: /etc/salt/minion
- require:
- pkg: minion_install
minion_peizhi:
file.managed:
- name: /etc/salt/minion
- source: salt://minion/files/minion
- mode: 640
- user: root
- template: jinja
[root@qing files]# cat minion | grep -v '#'
master: qing
id: {{grains['fqdn']}}
执行
salt-ssh 'xiaozhu' state.sls minion/init
注: 即时没启动minion 也可以获取grains信息
salt-ssh 'xiaozhu' grains.items