In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
Grains description
Grains is one of the most important components of Saltstack. The function of grains is the basic information of the controlled host of mobile phone, which is usually some static data, including CPU, kernel, operating system, virtualization and so on. On the server side, it can be flexibly customized according to this information, and administrators can use this information to customize different services.
Example: (janja template)
{% if grains ['os'] = =' Ubuntu'%} host: {{grains ['host']}} {% elif grains [' os'] = 'CentOS'%} host: {{grains [' fqdn]}} {% endif%} grains common operation commands
Match hosts with kernel version 2.6.32-358.14.1.el6.x86_64
Salt-G 'kernelrelease:2.6.32-358.14.1.el6.x8634 'cmd.run' uname-a'
Get grains entry information for all hosts
Salt'* 'grains.ls defines grains data
There are two ways to define grains data, one is to customize the configuration file on the controlled host, and the other is to implement it through the main control side extension module API. The difference is that modules are more flexible and can be dynamically defined through Python programming, while
Profiles are only suitable for relatively fixed keys and values. The following are explained separately:
1. Grains data customized by the host of the controlled end
[/ etc/salt/minion]
Default_include:minion.d/*.conf # Custom grains profile path
Grains configuration file: [/ etc/salt/minion.d/hostinfo.conf]
Grains: roles:-webserver-memcache deployment: datacenter4 cabinet: 13
Restart salt-minion to take effect: service salt-minion restart
Verify:
Salt 'wx' grains.item roles deployment cabinet
Results:
Salt 'wx' saltutil.sync_all
Result: the files are synchronized to the cache directory of the controlled terminal.
/ var/cache/salt/minion/extmods/grains/grains_openfile.py/var/cache/salt/minion/files/base/_grains/grains_openfile.py# Note: / var/cache/salt/minion/extmods/grains/ is the final storage location of the extension module files. After refreshing the module, the bytecode pyc;/var/cache/salt/minion/files/base/_grains/ will be produced in the same path as the temporary storage location.
Refresh module:
Salt 'wx' sys.reload_modules# generates pyc bytecode / var/cache/salt/minion/extmods/grains/grains_openfile.py/var/cache/salt/minion/extmods/grains/grains_openfile.pyc/var/cache/salt/minion/files/base/_grains/grains_openfile.py
Verify:
Salt 'wx' grains.item max_open_file
Results:
Wx:- max_open_file: 1024
Reference:
According to Liu Tiansi's "Python Automation Operation and maintenance Technology and Best practices"
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.