gocron/modules/ansible/ansible.go

29 lines
639 B
Go
Raw Normal View History

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
}