我想通过在我的file_roots目录according to the Salt manual here的_grains子目录中添加一个python脚本来添加自定义谷物(盐堆)到爪牙。难以在Salt中添加custome谷物
我的方法是让脚本读入文本文件并将数据解析为字典中的列表并将它们装载为颗粒(在这种情况下称为角色)。
我roles_file看起来是这样的:
appserver:minion1.example,minion2.example,minion3.exapmle
webserver:minion1.example
dbserver:minion2.example,minion3.example
,当读入一个dictioary看起来就像这样:
roles_list {
appserver: [minion1.example,minion2.example,minion3.example],
webserver: [minion1.example],
dbserver: [minino2.example, minion3.example]
}
的set_roles()
功能如下:
def set_roles():
"""
Set the 'roles' grain based on the host name.
"""
roles_list = {}
with open ('roles_file' ,'r') as inf:
for line in inf:
role , servers = line.partition(":")[::2]
roles_list[role] = (servers.rstrip()).split(',')
grains = {'roles': []}
hostname = _get_hostname() # defined elsewhere in my file
logger.debug('{0}'.format(roles_list))
for role, servers in roles_list.iteritems():
for server in servers:
if server == hostname:
grains['roles'].append(role)
return grains
这不起作用,角色不加载!我在这里错过了什么吗?
如何更好地调试?我知道set_roles()
函数在执行highstate或调用saltutil.sync_grains
时被调用。但我在哪里可以看到logger.debug
的输出?
首先,调用一个列表只是简单的混淆,所以我会重命名roles_list。我使用'minion1.example'作为主机名运行了一个快速测试,并且它工作正常。检查'主机名'的格式。 – RobertB