salt學習2_基礎命令

  1. 正則匹配

     # salt -E '192*' test.ping
     [WARNING ] Cannot resolve address None info via socket: <class 'socket.gaierror'>
     192.168.0.62:
     True
    
  2. 列表匹配
    #salt -L Minion,Minion1 test.ping

  3. Grians匹配
    #salt -G 'os:MacOS' test.ping
    其中os:MacOS是一組鍵值對

  4. 組匹配
    #salt -N groups test.ping.

  5. 復合匹配
    #salt -C 'G@os:MacOS or L@Minion1'
    支持使用and 和or 關聯多個條件

  6. Pillar值匹配
    #salt -I 'key:value' test.ping

  7. CIDR匹配
    #salt -s '192.168.1.0/24' test.ping

LP6A~L3[C]XQ$DDAQ4WE7R0.png

管理對象屬性:
Grains是saltstack組件中非常重要的組件之一
Grains是saltstack記錄Minion的一些靜態信息的組件,可以簡單理解為Grains里面記錄著每臺Minion的常用屬性比如:CPU,內存,磁盤,網絡信息。
可以通過:grains.items查看某臺Minion的所有Grains信息

簡單Grains的命令:
#salt '192.168.0.62' sys.list_functions grains
列出grains開頭的
#salt '192.168.0.62' sys.list_functions
列出所有
# salt '192.168.0.62' sys.doc grains.append
查看幫助信息

數據管理中心
Pillar在saltstack中主要作用就是存儲和定義配置管理中需要的一些數據,比如:軟件版本號,用戶名密碼等信息。
# cat minion | grep -C 4 pillar_roots
# Salt caches should be cleared.
#hash_type: sha256

    # The Salt pillar is searched for locally if file_client is set to local. If
    # this is the case, and pillar data is defined, then the pillar_roots need to
    # also be configured on the minion:
    #pillar_roots:
    #  base:
    #    - /srv/pillar

    # Set a hard-limit on the size of the files that can be pushed to the master.

知識補充:
如果在只是想匹配模式的上下幾行,grep可以實現。
$grep -5 'parttern' inputfile //打印匹配行的前后5行
$grep -C 5 'parttern' inputfile //打印匹配行的前后5行
$grep -A 5 'parttern' inputfile //打印匹配行的后5行
$grep -B 5 'parttern' inputfile //打印匹配行的前5行

在Master 配置文件中有一段Pillar setting選項專門定義Pillar相關的參數:

  1. 查看所有module列表
    #salt '*' sys.list_modules
  2. 查看指定module的所有function
    #salt '*' sys.list_functions cmd
  3. 查看指定module用法
    #salt '*' sys.doc cmd
  4. saltstack默認支持一次執行多個Module
    #salt '*' test.echo,cmd.run

states是saltstack中的配置語言

  1. 查看所有states列表
    #salt '*' sys.list_state_modules
  2. 查看指定states的所有function
    #salt '*' sys.list_state_functions file
  3. 查看file.states的詳細用法與例子
    #salt '*' sys.state_doc file.rename
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容