Ejemplo n.º 1
0
// PrepareFiles sets up the scripts required to install Chef.
func (i Installer) PrepareFiles() error {
	if i.skip() {
		log.Debug("Skipping setup of install scripts")
		return nil
	}
	log.Debug("Preparing install scripts")
	if err := i.writeWrapperScript(); err != nil {
		return err
	}
	return i.writeOmnibusScript()
}
Ejemplo n.º 2
0
func (p Provisioner) prepareJSON() error {
	log.Debug("Preparing JSON data")
	data := "{}\n"
	if p.Attributes != "" {
		data = p.Attributes
	}
	return ioutil.WriteFile(path.Join(p.SandboxPath, "dna.json"), []byte(data), 0644)
}
Ejemplo n.º 3
0
// NewDriver creates a new Vagrant driver that communicates with the given
// Vagrant machine. Under the hood `vagrant ssh-config` is executed to get a
// working SSH configuration for the machine.
func NewDriver(machine string, sshOptions, rsyncOptions []string) (*Driver, error) {
	if machine == "" {
		machine = DefaultMachine
	}

	log.Debug("Asking Vagrant for SSH config")
	cmd := goexec.Command("vagrant", "ssh-config", machine)
	var stdout, stderr bytes.Buffer
	cmd.Stdout = &stdout
	cmd.Stderr = &stderr
	if err := cmd.Run(); err != nil {
		msg := fmt.Sprintf("`vagrant ssh-config` failed with output:\n\n%s",
			strings.TrimSpace(stderr.String()))
		return nil, errors.New(msg)
	}

	configFile := path.Join(ConfigPath, "machines", machine, "ssh_config")
	log.Debug("Writing current SSH config to", configFile)
	if err := os.MkdirAll(path.Dir(configFile), 0755); err != nil {
		return nil, err
	}
	if err := ioutil.WriteFile(configFile, stdout.Bytes(), 0644); err != nil {
		return nil, err
	}

	sshClient := &openssh.Client{
		Host:       "default",
		ConfigFile: configFile,
		Options:    sshOptions,
	}

	rsyncClient := *rsync.MirrorClient
	rsyncClient.RemoteHost = "default"
	rsyncClient.RemoteShell = sshClient.Shell()
	rsyncClient.Options = rsyncOptions

	return &Driver{machine, sshClient, &rsyncClient}, nil
}
Ejemplo n.º 4
0
// Resolve resolves cookbook dependencies using the named resolver. If no
// resolver is specified, it will be guessed based on the files present in the
// current directory. After resolving dependencies, all non-cookbook files will
// be deleted as well.
func Resolve(name, dst string) error {
	log.Debug("Preparing cookbooks")

	r, err := findResolver(name, dst)
	if err != nil {
		return err
	}

	log.Infof("Installing cookbook dependencies with %s resolver\n", r.Name())
	if err := r.Resolve(dst); err != nil {
		return err
	}

	log.Info("Stripping non-cookbook files")
	return stripCookbooks(dst)

}
Ejemplo n.º 5
0
func (p Provisioner) prepareSoloConfig() error {
	log.Debug("Preparing Chef Solo config")
	data := fmt.Sprintf("cookbook_path \"%s\"\n", path.Join(p.RootPath, "cookbooks"))
	data += "ssl_verify_mode :verify_peer\n"
	return ioutil.WriteFile(path.Join(p.SandboxPath, "solo.rb"), []byte(data), 0644)
}