设为首页 收藏本站
查看: 1326|回复: 0

[经验分享] SaltStack Char02 组件

[复制链接]

尚未签到

发表于 2018-1-3 16:57:33 | 显示全部楼层 |阅读模式
  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>  

  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\ntwo\nthree\nfour\nfive\n'
  

  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

  ->  - 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 流程

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-431233-1-1.html 上篇帖子: saltstack常用模块 下篇帖子: 车到山前没有路,扔了骑车去跑步
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表