2017-03-10 09:08:51 +00:00
|
|
|
package ansible
|
|
|
|
|
2017-03-24 09:55:44 +00:00
|
|
|
// ansible ad-hoc 命令封装
|
2017-03-10 09:08:51 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2017-03-23 05:58:42 +00:00
|
|
|
"github.com/ouqiang/cron-scheduler/modules/utils"
|
2017-03-10 09:08:51 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 执行ad-hoc
|
2017-03-24 09:55:44 +00:00
|
|
|
* hosts 主机名或主机别名 逗号分隔
|
|
|
|
* hostFile 主机名文件
|
2017-03-10 09:08:51 +00:00
|
|
|
* module 调用模块
|
|
|
|
* args 传递给模块的参数
|
|
|
|
*/
|
2017-03-24 09:55:44 +00:00
|
|
|
func ExecCommand(hosts string, hostFile string, args... string) (output string, err error) {
|
|
|
|
if hosts== "" || hostFile == "" || len(args) == 0 {
|
2017-03-10 09:08:51 +00:00
|
|
|
err = errors.New("参数不完整")
|
|
|
|
return
|
|
|
|
}
|
2017-03-24 09:55:44 +00:00
|
|
|
commandArgs := []string{hosts, "-i", hostFile}
|
|
|
|
commandArgs = append(commandArgs, args...)
|
2017-03-10 09:08:51 +00:00
|
|
|
output, err = utils.ExecShell("ansible", commandArgs...)
|
|
|
|
|
|
|
|
return
|
2017-03-24 09:55:44 +00:00
|
|
|
}
|