2.1
Target : 管理的对象
Master上,通过采用不同的Target去管理不同的Minion
Salt命令的Target Options 参数信息
1 正则匹配
#salt -E 'TestS*' test.ping
2 列表匹配
#salt -L TestSlave_1,TestSlave1_Audio test.ping
#salt -L ‘TestSlave_1,TestSlave1_Audio’ test.ping
3 Grains匹配
#salt -G 'os:Ubuntu' test.ping
4 组匹配
#salt -N groups test.ping
5 复合匹配
#salt -C 'G@os:MacOS or L@Minion1' test.ping
6 Pillar值匹配
7 CIDR匹配
2.2 管理对象的属性
Grains
2.2.1 通过Minion配置文件定义Grains ???
2.2.2 通过Grains模块定义Grains
2.3 数据管理中心
Pillar在SaltStack中主要的作用就是存储和定义配置管理中需要的一些数据,比如软件版本号、用户名密码等信息,它的定
2.4 针对管理对象的操作
1 查看所有的module列表
salt '*' sys.list_modules
2 查看制定module的所有function
# salt TestSlave1_Audio sys.list_functions cmd TestSlave1_Audio: - 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
2.3 查看指定module用法
# salt TestSlave1_Audio sys.doc cmd.run'cmd.run:' Execute the passed command and return the output as a string Note that ``env`` represents the environment variables for the command, and should be formatted as a dict, or a YAML string which resolves to a dict. Warning: This function does not process commands through a shell unless the python_shell flag is set to True. This means that any shell-specific functionality such as 'echo' or the use of pipes, redirection or &&, should either be migrated to cmd.shell or have the python_shell=True flag set here. The use of python_shell=True means that the shell will accept _any_ input including potentially malicious commands such as 'good_command;rm -rf /'. Be absolutely certain that you have sanitized your input prior to using python_shell=True CLI Example: salt '*' cmd.run "ls -l | awk '/foo/{print $2}'" The template arg can be set to 'jinja' or another supported template engine to render the command arguments before execution. For example: salt '*' cmd.run template=jinja "ls -l /tmp/{{grains.id}} | awk '/foo/{print $2}'" Specify an alternate shell with the shell parameter: salt '*' cmd.run "Get-ChildItem C: " shell='powershell' A string of standard input can be specified for the command to be run using the ``stdin`` parameter. This can be useful in cases where sensitive information must be read from standard input.: salt '*' cmd.run "grep f" stdin='one two three four five ' If an equal sign (``=``) appears in an argument to a Salt command it is interpreted as a keyword argument in the format ``key=val``. That processing can be bypassed in order to pass an equal sign through to the remote shell command by manually specifying the kwarg: salt '*' cmd.run cmd='sed -e s/=/:/g'
2.5 配置管理
States 是 SaltStack中的配置语言
2.5.1 查看所有的states列表
# salt TestSlave1_Audio sys.list_state_modules | head -10 TestSlave1_Audio: - acl - alias - alternatives - apt - archive - artifactory - blockdev - buildout - cloud
2.5.2 查看制定states中的所有function
2.5.3 查看制定states用法
# salt TestSlave1_Audio sys.list_state_modules.apt | head -10 TestSlave1_Audio: 'sys.list_state_modules.apt' is not available. root@Ly-banya:~# salt TestSlave1_Audio sys.state_doc file | head -10 TestSlave1_Audio: ---------- file: Operations on regular files, special files, directories, and symlinks ===================================================================== Salt States can aggressively manipulate files on a system. There are a number of ways in which files can be managed.
2.5.4 查看制定states指定function用法
2.5.5 从一个简单的实例去了解states
# cat foo.conf SaltStack Books root@Ly:/srv/salt# cat one.sls /tmp/foo.conf: file.managed: - source: salt://foo.conf - user: root - group: root - mode: 644 - backup: minion :/srv/salt# salt TestSlave1_Audio state.sls one TestSlave1_Audio: ---------- ID: /tmp/foo.conf Function: file.managed Result: True Comment: File /tmp/foo.conf is in the correct state Started: 06:26:43.545952 Duration: 7.644 ms Changes: Summary ------------ Succeeded: 1 Failed: 0 ------------ Total states run: 1
2.6 执行结果处理
Return 组件可以理解为SaltStack系统对执行Minion返回后的数据进行存储或者返回给其他程序,它支持多种存储,比如MySQL , MonogDB 、Redis
通过Return 我们可以对SaltStack的每次操作进行记录,以后可以用来日志审计
2.6.1 查看所有Return 列表
# salt TestSlave1_Audio sys.list_returners TestSlave1_Audio: - carbon - couchdb - etcd - hipchat - local - local_cache - multi_returner - slack - smtp - sqlite3 - syslog
2.6.2 Return 流程