1、自定义一个模块重命名的文件、
[root@cenots7 salt]# cat /srv/salt/_modules/test.py
__virtualname__ = 'hello'
def __virtual__():
return __virtualname__
def test():
return 'hello world, this is test custom modules'
2、修改自定义模块后要记得同步、
[root@cenots7 salt]# salt '*103' saltutil.sync_modules
minion103:
- modules.test
3、调用自定义模块、
[root@cenots7 salt]# salt '*103' test.test
minion103:
Module 'test' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' hello
minion103:
Module 'hello' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' test.hello
minion103:
Module 'test' is not available.
ERROR: Minions returned with non-zero exit code
[root@cenots7 salt]# salt '*103' hello.test
minion103:
hello world, this is test custom modules
1、修改/etc/salt/master中module_dirs、指向/srv/salt/_module、如下:
module_dirs:
- /srv/salt/_modules
2、创建/srv/salt/_modules/
[root@cenots7 salt]# mkdir -p /srv/salt/_modules/
3、编写自定义模块、
[root@cenots7 salt]# cat /srv/salt/_modules/temp.py
#!/usr/bin/env python
# -*- encoding: utf8 -*-
def test():
print "hello world"
return "how do you do"
4、将模块同步到minion、
[root@cenots7 salt]# salt '*' saltutil.sync_modules
minion103:
- modules.temp
minion104:
- modules.temp
5、调用自定义的模块、
[root@cenots7 salt]# salt '*' temp.test
minion103:
how do you do
minion104:
how do you do