Instantly share code, notes, and snippets.

Embed
What would you like to do?
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