22
21
// Host is the host to configure, in the format [user@]hostname.
24
// Client is the SSH client to connect with.
25
// If Client is nil, ssh.DefaultClient will be used.
25
28
// Config is the cloudinit config to carry out.
26
29
Config *cloudinit.Config
28
// Stdin is required to respond to sudo prompts,
29
// and must be a terminal (except in tests)
32
// Stdout is required to present sudo prompts to the user.
35
31
// Stderr is required to present bootstrap progress to the user.
40
36
// and executes a script that carries out cloud-config.
41
37
func Configure(params ConfigureParams) error {
42
38
logger.Infof("Provisioning machine agent on %s", params.Host)
43
script, err := generateScript(params.Config)
39
script, err := ConfigureScript(params.Config)
47
scriptBase64 := base64.StdEncoding.EncodeToString([]byte(script))
48
script = fmt.Sprintf(`F=$(mktemp); echo %s | base64 -d > $F; . $F`, scriptBase64)
51
[]string{"sudo", fmt.Sprintf("bash -c '%s'", script)},
54
cmd.Stdout = params.Stdout
43
logger.Debugf("running script on %s: %s", params.Host, script)
44
client := params.Client
46
client = ssh.DefaultClient
48
cmd := ssh.Command(params.Host, []string{"sudo", "/bin/bash"}, nil)
49
cmd.Stdin = strings.NewReader(script)
55
50
cmd.Stderr = params.Stderr
56
cmd.Stdin = params.Stdin
60
// generateScript generates the script that applies
54
// ConfigureScript generates the bash script that applies
61
55
// the specified cloud-config.
62
func generateScript(cloudcfg *cloudinit.Config) (string, error) {
56
func ConfigureScript(cloudcfg *cloudinit.Config) (string, error) {
63
57
// TODO(axw): 2013-08-23 bug 1215777
64
58
// Carry out configuration for ssh-keys-per-user,
65
59
// machine-updates-authkeys, using cloud-init config.