cp模块(实现远程文件、目录的复制,以及下载URL文件等操作)(参数 cache_local_file、get_file、get_dir、get_url)
- 将主服务器file_roots指定位置下的目录复制到被控主机
salt '*' cp.get_dir [salt://hellotest](salt://hellotest) /data
- 将主服务器file_roots指定位置下的文件复制到被控主机
salt '*' cp.get_file [salt://hellotest/rocketzhang](salt://hellotest/rocketzhang) /root/rocketzhang
- 下载指定URL内容到被控主机指定位置
salt '*' cp.get_url [http://xxx.xyz.com/download/0/files.tgz](http://xxx.xyz.com/download/0/files.tgz) /root/files.tgz
- API调用
client.cmd('*','cp.get_dir',['[salt://path/to/dir','/minion/dest'])](salt://path/to/dir)
- cmd模块(实现远程的命令行调用执行,默认是root权限,使用注意)
salt '*' cmd.run 'netstat -ntlp'
-
API调用:client.cmd('*','cmd.run',['命令'])
★此模块较常用,可实现多个模块的功能。 -
cron模块(实现被控主机的crontab操作)(raw_cron查,cron.set_job加,rm_job删)
-
为指定的被控主机、root用户添加crontab信息
salt '*' cron.set_job root '*/5' '*' '*' '*' '*' 'date >/dev/null 2>&1'
salt '*' cron.raw_cron root
- 删除指定的被控主机、root用户的crontab信息
salt '*' cron.rm_job root 'date >/dev/null 2>&1'
-
API调用:client.cmd('*','cron.rm_job',['root','命令']
-
dnsutil模块(实现被控主机通用DNS操作)
为被控主机添加指定的hosts主机配置项
salt '*' dnsutil.hosts_append /etc/hosts 127.0.0.1 [test.com](http://test.com/)
-
API调用:client.cmd('*','dnsutil.hosts_remove',['/etc/hosts','域名']
-
file模块(被控主机文件常见操作,包括文件读写、权限、查找、校验等)(参数有check_hash md5加密值对比、get_sum 指定加密方式、chown、copy、dirctory_exists目录是否存在、stats、get_mode、set_mode、mkdir、sed内容修改、append追加、remove)
salt '*' file.get_sum /etc/resolv.conf md5
salt '*' file.stats /etc/resolv.conf
-
API调用:client.cmd('*',fiel.append /文件 "增加字段")
-
archive模块,在系统层面实现压缩包的调用(gzip,gunzip,tar,unzip等)
salt '*' archive.gzip /tmp/abc.txt
-
API调用:client.cmd('*','archive.gunzip ',['/tmp/qq.gz'])
-
network模块(返回被控主机网络信息)(参数有 dig、ping、traceroute 跟域名,hwaddr 跟网卡、in_subnet 跟网段、interfaces、ip_addrs、subnet 无字段)
salt '*' network.ip_addrs
salt '*' network.interfaces
-
API调用:client.cmd('*','network.in_subnet','网段')
-
pkg包管理模块(被控主机程序包管理,如yum、apt-get等)(参数有 install、remove 跟软件包,upgrade升级所有)
salt '*' pkg.install nmap
salt '*' pkg.file_list nmap
-
API调用:client.cmd('*','pkg.upgrade')
-
service 服务模块(被控主机程序包服务管理)(参数有 enable、disable、reload、restart、start、stop、status)
salt '*' service.enable crond
salt '*' service.reload crond
- API调用:client.cmd('*','service.stop' 'httpd')
注意: 使用模块操作时,请先测试命令是否有问题,没有问题再次执行
- 例如:
salt "*" cmd.run "ifconfig" test
网友评论