Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use grains of saltstack and cmd.run.md (4)

2025-02-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

How to use saltstack grains and cmd.run.md (4), many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

Grains.items is mainly used to collect minion information, facilitate information collection, follow-up piller use, automatically match configuration files according to hardware information, and so on.

Basic usage

Grains.ls

Salt'* 'grains.ls displays the item of all minion

Grains.items

Salt'* 'grains.items displays the item values of all minion

Grains.item

Salt'* 'grains.item os displays information about os. As follows: root@salt ~ # salt 'sa10-003' grains.item ossa10-003: os: RedHat

If you want to obtain multiple item at the same time, you can directly relate to the item after a space, as follows:

Root@salt ~ # salt 'sa10-003' grains.item os osrelease oscodenamesa10-003: os: RedHat oscodename: Tikanga osrelease: 5.8

Custom grains: first of all, create a directory _ grains under the root directory of salt (/ srv/salt)

Mkdir / srv/salt/_grainscd / srv/salt/_grains

Suppose I want to fetch the memory on the minion side as follows: vim mem.py

#-*-coding: utf-8-* -''Module for squid disk information by python'''import commandsimport osdef cache ():' 'Return the memory usage information for volumes mounted on this minion' 'grains= {} m = commands.getoutput ("free-g | awk' $0~/Mem/ {print$2+1}'") grains ['mem_test'] = int (m) return grains

Synchronize to the minion side

Root@salt _ grains # salt 'sa10-003' saltutil.sync_all sa10-003:-grains:-grains.mem # has been synchronized over modules: outputters: renderers: returners: states:

If you need to change the module, after the change is complete, you can use the following command to overload:

Salt sa10-003 sys.reload_modules

Verify the previous custom grains:

Root@salt _ grains # salt sa10-003 grains.item mem_testsa10-003: mem_test: 2

Memory information of sa10-003:

[root@sa10-003 salt] # free-m total used free shared buffers cachedMem: 2012 1766 246 0 286 1207 Melissa + buffers/cache: 272 1739Swap: 00

The information obtained by customizing grains on saltmaster is the same as that of this machine.

In addition to the items that comes with salt and our custom items, we can also use the shell command to achieve our goal; of course, this requires another powerful command of salt, cmd.run. I want to get the memory information of sa10-003. you can use the following command:

Root@salt _ grains # salt sa10-003 cmd.run 'free-m'sa10-003: total used free shared buffers cached Mem: 2012 1769 242 0 286 1207-/ + buffers/cache: 275 1736 Swap: 00

Cmd.run operates on the master side, followed by system-related shell commands. In this way, almost all the commands on the minion side can be realized.

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report