查看saltstack 支持使用的module
salt -s “target” sys.list_modules
salt -s “jinkeen-ubuntu” sys.list_functions cmd
salt -s “jinkeen-ubuntu” sys.doc cmd|less
salt -s "ginkgo" sys.list_modules
ginkgo:
- acl
- aliases
- alternatives
- apache
- archive
- artifactory
- at
- beacons
- bigip
- blockdev
- bridge
- btrfs
- buildout
- cloud
- cmd
- composer
- config
- consul
- container_resource
- cp
- cron
- data
- defaults
- devmap
- dig
- disk
- django
- dnsmasq
- dnsutil
- drbd
- environ
- etcd
- ethtool
- event
- extfs
- file
- gem
- genesis
- grafana4
- grains
- group
- grub
- hashutil
- hipchat
- hosts
- http
- incron
- infoblox
- ini
- inspector
- introspect
- ip
- ipset
- iptables
- jboss7
- jboss7_cli
- k8s
- key
- keyboard
- kmod
- libcloud_dns
- locale
- locate
- log
- logrotate
- lowpkg
- lvm
- match
- mattermost
- mine
- minion
- modjk
- mount
- msteams
- nagios_rpc
- namecheap_domains
- namecheap_domains_dns
- namecheap_domains_ns
- namecheap_ssl
- namecheap_users
- network
- nova
- openscap
- openstack_config
- pagerduty
- pagerduty_util
- pam
- pecl
- pillar
- pip
- pkg
- pkg_resource
- postfix
- ps
- publish
- pushover
- pyenv
- raid
- random
- random_org
- rbenv
- rest_sample_utils
- restartcheck
- ret
- rvm
- s3
- s6
- salt_proxy
- saltutil
- schedule
- scsi
- sdb
- seed
- serverdensity_device
- service
- shadow
- slack
- slsutil
- smtp
- solrcloud
- sqlite3
- ssh
- state
- status
- statuspage
- supervisord
- sys
- sysctl
- sysfs
- syslog_ng
- system
- telemetry
- temp
- test
- timezone
- udev
- uptime
- user
- vault
- vbox_guest
- virtualenv
- vsphere
- webutil
- xfs
- zenoss
常用模块:cmd, cron, file, mount, ntp, pkg, service, user, group
查看模块的功能:
salt -s "jinkeen-ubuntu" sys.list_functions cmd
jinkeen-ubuntu:
- cmd.exec_code
- cmd.exec_code_all
- cmd.has_exec
- cmd.retcode
- cmd.run
- cmd.run_all
- cmd.run_chroot
- cmd.run_stderr
- cmd.run_stdout
- cmd.script
- cmd.script_retcode
- cmd.shell
- cmd.shells
- cmd.tty
- cmd.which
- cmd.which_bin
查询用法:
salt -s "jinkeen-ubuntu" sys.doc cmd|less
cmd.run:在minion上执行命令(默认是root权限,慎用),返回值是命令结果,命令没有执行结果时,返回为空
salt "*" cmd.run "free -m "
ginkgo:
total used free shared buffers cached
Mem: 996 840 155 0 119 133
-/+ buffers/cache: 587 408
Swap: 0 0 0
cmd.script:在minion上执行master上的脚本
salt '*' cmd.script salt://scripts/runme.sh 'arg1 arg2 "arg 3"'
crond 模块:
为指定的被控主机、root用户添加crontab信息
salt -s "ginkgo" sys.list_functions cron
ginkgo:
- cron.list_tab
- cron.ls
- cron.raw_cron
- cron.rm
- cron.rm_env
- cron.rm_job
- cron.rm_special
- cron.sdecode
- cron.set_env
- cron.set_job
- cron.set_special
- cron.write_cron_file
- cron.write_cron_file_verbose
salt ‘*’ cron.list_tab root
flie 模块
被控主机文件常见操作,包括文件读写、权限、查找、校验等
salt -s "ginkgo" sys.list_functions file
ginkgo:
- file.access
- file.append
- file.apply_template_on_contents
- file.basename
- file.blockreplace
- file.check_file_meta
- file.check_hash
- file.check_managed
- file.check_managed_changes
- file.check_perms
- file.chgrp
- file.chown
- file.comment
- file.comment_line
- file.contains
- file.contains_glob
- file.contains_regex
- file.copy
- file.delete_backup
- file.directory_exists
- file.dirname
- file.diskusage
- file.extract_hash
- file.file_exists
- file.find
- file.get_devmm
- file.get_diff
- file.get_gid
- file.get_group
- file.get_hash
- file.get_managed
- file.get_mode
- file.get_selinux_context
- file.get_source_sum
- file.get_sum
- file.get_uid
- file.get_user
- file.gid_to_group
- file.grep
- file.group_to_gid
- file.is_blkdev
- file.is_chrdev
- file.is_fifo
- file.is_link
- file.join
- file.lchown
- file.line
- file.link
- file.list_backup
- file.list_backups
- file.list_backups_dir
- file.lstat
- file.makedirs
- file.makedirs_perms
- file.manage_file
- file.mkdir
- file.mknod
- file.mknod_blkdev
- file.mknod_chrdev
- file.mknod_fifo
- file.move
- file.normpath
- file.open_files
- file.pardir
- file.patch
- file.path_exists_glob
- file.prepend
- file.psed
- file.read
- file.readdir
- file.readlink
- file.remove
- file.remove_backup
- file.rename
- file.replace
- file.restore_backup
- file.restorecon
- file.rmdir
- file.search
- file.sed
- file.sed_contains
- file.seek_read
- file.seek_write
- file.set_mode
- file.set_selinux_context
- file.source_list
- file.stats
- file.statvfs
- file.symlink
- file.touch
- file.truncate
- file.uid_to_user
- file.uncomment
- file.user_to_uid
- file.write
mount 模块
salt -s “ginkgo” sys.list_functions mount
ginkgo:
- mount.active
- mount.automaster
- mount.fstab
- mount.is_fuse_exec
- mount.is_mounted
- mount.mount
- mount.remount
- mount.rm_automaster
- mount.rm_fstab
- mount.rm_vfstab
- mount.set_automaster
- mount.set_fstab
- mount.set_vfstab
- mount.swapoff
- mount.swapon
- mount.swaps
- mount.umount
- mount.vfstab
- CP module
salt中文件分发的方法:
salt-cp
salt-cp命令用于复制一个文件到多个minion系统中。指定minion可以使用通配符、正则表达式、Grains等方法,不能分配目录
salt-cp '*' [ options ] SOURCE DEST
salt-cp -E '.*' [ options ] SOURCE DEST
salt-cp -G 'os:CentOS*' [ options ] SOURCE DEST
minion匹配
-E 目标选择;表示以正则表达式匹配minion
-G 目标选择表示使用minion上的Salt Graings系统的返回值来匹配特定minion
salt-cp
salt-cp '*' [ options ] SOURCE DEST
salt-cp -E '.*' [ options ] SOURCE DEST
salt-cp -G 'os:CentOS*' [ options ] SOURCE DEST
# salt-cp "*" /srv/salt/test_remove /mnt
172.17.36.79:
----------
/mnt/test_remove:
True
返回True 表示成功,否则就是失败
将test_remove 文件 发送到 OS为CentOS的minion的 /mnt 目录下
salt-cp -G "os:CentOS" /srv/salt/test_remove /mnt
172.17.36.79:
----------
/mnt/test_remove:
True
表示成功
salt-cp -G "os:ubuntu" /srv/salt/test_remove /mnt
jinkeen-ubuntu:
----------
/mnt/test_remove:
True
使用salt中的cp 模块
salt -s "jinkeen-ubuntu" sys.list_functions cp
jinkeen-ubuntu:
- cp.cache_dir
- cp.cache_file
- cp.cache_files
- cp.cache_local_file
- cp.cache_master
- cp.get_dir
- cp.get_file
- cp.get_file_str
- cp.get_template
- cp.get_url
- cp.hash_file
- cp.is_cached
- cp.list_master
- cp.list_master_dirs
- cp.list_master_symlinks
- cp.list_minion
- cp.list_states
- cp.push
- cp.push_dir
- cp.recv
cp 模块可以作用于目录
- cp.get_file
cp.get_file用来从master下载文件到客户端,可以外加几个参数,比如没有文件夹,创建文件夹的makedirs=True ,压缩的gzip参数
salt "jinkeen-ubuntu" cp.get_file salt://test_remove /mnt/file
jinkeen-ubuntu:
/mnt/file
salt "jinkeen-ubuntu" cp.get_file salt://test_remo /mnt/file
jinkeen-ubuntu:
成功和失败的区别:少了确认信息 */mnt/file*
get_url
cp.get_url可以从一个URL地址下载文件,URL可以是msater上的路径(salt://),也可以是http网址。
salt '*' cp.get_url salt://my/file /tmp/mine
salt '*' cp.get_url http://47.93.233.37/test /tmp/test
get_template
在文件下载之前用模板引擎处理。
salt ‘*’ cp.get_template salt://path/to/template /minion/destpush
从客户端传文件到master上,处于很明显的安全考虑,默认没有启用此功能,如果你需要的话可以很方便的开启。
打开master 的配置文件中的
file_recv: True
执行:salt 'minion-id' cp.push /path/to/the/file
上传上来的文件在master的:
/var/cache/salt/master/minions
service 模块
ctions' is not available.
[root@Ginkgo ~]# salt -s "ginkgo" sys.list_functions service
ginkgo:
- service.available
- service.delete
- service.disable
- service.disabled
- service.enable
- service.enabled
- service.get_all
- service.get_disabled
- service.get_enabled
- service.missing
- service.reload
- service.restart
- service.start
- service.status
- service.stop