Skip to content

Instantly share code, notes, and snippets.

@kevinburke
Created December 10, 2016 23:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinburke/079726dace3761097c6c70fe1e084912 to your computer and use it in GitHub Desktop.
Save kevinburke/079726dace3761097c6c70fe1e084912 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"flag"
"io/ioutil"
"log"
"path/filepath"
"time"
"github.com/kevinburke/ansible-go/core"
"github.com/kevinburke/ansible-go/user"
yaml "gopkg.in/yaml.v2"
)
type Config struct {
HostName string `yaml:"host"`
HostUser string `yaml:"user"`
}
const groupname = "summersaquatic"
const username = "summersaquatic"
func Provision(ctx context.Context) error {
if err := core.AddGroup(ctx, groupname, core.GroupOpts{}); err != nil {
return err
}
if err := user.Add(ctx, username, user.Group(groupname), user.AppendGroups(), user.Shell("/bin/bash")); err != nil {
return err
}
// TODO pull this from user.Add().Homedir?
homedir := filepath.Join("/home", username)
if err := core.CreateDirectory(ctx, filepath.Join(homedir, ".ssh"), core.DirOpts{Mode: 0755}); err != nil {
return err
}
if err := core.CreateDirectory(ctx, filepath.Join(homedir, "public"), core.DirOpts{Mode: 0755}); err != nil {
return err
}
if err := core.CreateDirectory(ctx, filepath.Join(homedir, "public", ".well-known"), core.DirOpts{Mode: 0755}); err != nil {
return err
}
return nil
}
func main() {
cfg := flag.String("config", "config.yml", "Path to a config file")
dur := flag.Duration("duration", 10*time.Minute, "Amount of time to wait")
flag.Parse()
data, err := ioutil.ReadFile(*cfg)
if err != nil {
log.Fatal(err)
}
c := new(Config)
if err := yaml.Unmarshal(data, c); err != nil {
log.Fatal(err)
}
flag.Parse()
ctx, cancel := context.WithTimeout(context.Background(), *dur)
defer cancel()
if err := Provision(ctx); err != nil {
log.Fatal(err)
}
log.Fatal("foo")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment