func (_ *UserTask) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *UserTask) error { args := buildUseraddArgs(e) cmd := []string{"useradd"} cmd = append(cmd, args...) glog.Infof("Creating user %q", e.Name) t.AddCommand(cloudinit.Once, cmd...) return nil }
func (_ *Service) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *Service) error { serviceName := e.Name servicePath := path.Join(systemdSystemPath, serviceName) err := t.WriteFile(servicePath, fi.NewStringResource(*e.Definition), 0644, 0755) if err != nil { return err } if fi.BoolValue(e.ManageState) { t.AddCommand(cloudinit.Once, "systemctl", "daemon-reload") t.AddCommand(cloudinit.Once, "systemctl", "start", "--no-block", serviceName) } return nil }
func (_ *Package) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *Package) error { if e.Source != nil { localFile := path.Join(localPackageDir, e.Name) t.AddMkdirpCommand(localPackageDir, 0755) url := *e.Source t.AddDownloadCommand(cloudinit.Always, url, localFile) t.AddCommand(cloudinit.Always, "dpkg", "-i", localFile) } else { packageSpec := e.Name if e.Version != nil { packageSpec += " " + *e.Version } t.Config.Packages = append(t.Config.Packages, packageSpec) } return nil }
func (_ *File) RenderCloudInit(t *cloudinit.CloudInitTarget, a, e, changes *File) error { dirMode := os.FileMode(0755) fileMode, err := fi.ParseFileMode(fi.StringValue(e.Mode), 0644) if err != nil { return fmt.Errorf("invalid file mode for %q: %q", e.Path, e.Mode) } if e.Type == FileType_Symlink { t.AddCommand(cloudinit.Always, "ln", "-s", fi.StringValue(e.Symlink), e.Path) } else if e.Type == FileType_Directory { parent := filepath.Dir(strings.TrimSuffix(e.Path, "/")) t.AddCommand(cloudinit.Once, "mkdir", "-p", "-m", fi.FileModeToString(dirMode), parent) t.AddCommand(cloudinit.Once, "mkdir", "-m", fi.FileModeToString(dirMode), e.Path) } else if e.Type == FileType_File { err = t.WriteFile(e.Path, e.Contents, fileMode, dirMode) if err != nil { return err } } else { return fmt.Errorf("File type=%q not valid/supported", e.Type) } if e.Owner != nil || e.Group != nil { t.Chown(e.Path, fi.StringValue(e.Owner), fi.StringValue(e.Group)) } if e.OnChangeExecute != nil { t.AddCommand(cloudinit.Always, e.OnChangeExecute...) } return nil }