zoukankan      html  css  js  c++  java
  • saltstack笔记

    一.grains的两种使用方法:参考http://www.21yunwei.com/archives/3155

    1. minion端:脚本:vim /etc/salt/minion.d/*.conf
      [root@99bill minion.d]# pwd
      /etc/salt/minion.d
      [root@99bill minion.d]# ls
      _schedule.conf  test.conf
      [root@99bill minion.d]# cat test.conf
      grains:
          name:
            -lanxiaohui
      

       测试:

      [root@99bill minion.d]# salt 'minion102' grains.item name
      minion102:
          ----------
          name:
              -lanxiaohui
      

        

       

    2. master端:vim /srv/salt/_grains/cpu.py通过python脚本写入grains读取系统信息
      #!/usr/bin/python
      #coding:utf-8
      import os
      
      def cpu():
          grains = {}
          command = "top -b -n 1 | grep Cpu | awk -F'[:,]' '{print $5}'"
          with os.popen(command) as file:
              grains["cpu_id"] = file.read()
          return grains
      

        master端执行

      salt '*' saltutil.sync_all
      salt '*' sys.reload_modules
      查看效果
      salt '*' grains.item cup_id

        静态数据:vim /srv/salt/_grains/test.py

      #!/usr/bin/python
      #coding:utf-8
      
      def test():
          grains = {}
          grains['test_key'] = 'test sign'
          return grains
      

        

          master端执行

    salt '*' saltutil.sync_all
    salt '*' sys.reload_modules
         查看效果
     salt '*' grains.item test_key
    

     二.pillar使用方法: vim /etc/salt/master

        

    pillar_roots:
      base:
        - /srv/pillar
    

     vim /srv/pillar/top.sls

    base:
        'minion102':
          - data
        'minion104':
          - data
    

     vim /srv/pillar/data.sls

    name: lanxiaohui
    age: 18
    language:
        - php
        - js
        - python
    cpu: {{ grains.cpu_id }}  #调用grains变量
    

     测试:

    [root@99bill pillar]# salt '*' pillar.data language
    minion105:
        ----------
    minion106:
        ----------
    minion102:
        ----------
        language:
            - php
            - js
            - python
    minion103:
        ----------
    minion104:
        ----------
        language:
            - php
            - js
            - python
    [root@99bill pillar]# salt '*' pillar.data cpu
    minion103:
        ----------
    minion106:
        ----------
    minion104:
        ----------
        cpu:
            93.9 id
    minion105:
        ----------
    minion102:
        ----------
        cpu:
            93.8 id
    [root@99bill pillar]# 
    

            

  • 相关阅读:
    JS闭包应用-私有变量、柯里化、偏函数
    JS限流与防抖
    JS自定义事件与事件代理
    CSS 去除图片和父元素底部间隙
    logstash使用http收集日志送Kafka
    shell中if条件语句结尾fi前面如果有&可以没有;
    filebeat 采集日志送Kafka
    JavaScript通过reduce+递归实现树的深度遍历
    WebStorm配置vueCli+eslint+prettier保存自动格式化
    ECMAScript 6 promise
  • 原文地址:https://www.cnblogs.com/feigerlan/p/9554945.html
Copyright © 2011-2022 走看看