예제 #1
0
func (t *Template) Run() error {
	defer urknall.OpenLogger(os.Stdout).Close()
	var target urknall.Target
	var err error
	if t.Password != "" {
		target, err = urknall.NewSshTargetWithPassword(t.UserName+"@"+t.Host, t.Password)

	} else {
		if len(strings.TrimSpace(t.Host)) <= 0 || t.Host == LOCALHOST {
			target, err = urknall.NewLocalTarget()
		} else {
			target, err = urknall.NewSshTarget(t.UserName + "@" + t.Host) //this is with sshkey
		}
	}
	if err != nil {
		return err
	}

	runner, err := get(t.Name)

	if err != nil {
		log.Errorf("fatal error, couldn't locate the package %s", t.Name)
		return err
	}

	if initializeRunner, ok := runner.(TemplateRunnable); ok {
		initializeRunner.Options(t)
		return initializeRunner.Run(target)
	}
	return errors.New(fmt.Sprintf("fatal error, couldn't locate the package %q", t.Name))
}
예제 #2
0
func run() error {
	defer urknall.OpenLogger(os.Stdout).Close()
	var target urknall.Target
	var e error
	uri := "*****@*****.**"
	password := ""
	if password != "" {
		target, e = urknall.NewSshTargetWithPassword(uri, password)
	} else {
		target, e = urknall.NewSshTarget(uri)
	}
	if e != nil {
		return e
	}
	return urknall.Run(target, &Template{})
}
예제 #3
0
func provision() error {
	// setup logging to stdout
	defer urknall.OpenLogger(os.Stdout).Close()

	// create a basic urknall.Template
	// executes "echo hello world" as user ubuntu on the provided host
	tpl := urknall.TemplateFunc(func(p urknall.Package) {
		p.AddCommands("run", Shell("echo hello world"))
	})

	// create provisioning target for provisioning via ssh with
	// user=ubuntu
	// host=172.16.223.142
	// password=ubuntu
	target, e := urknall.NewSshTargetWithPassword("[email protected]", "ubuntu")
	if e != nil {
		return e
	}
	return urknall.Run(target, tpl)
}