Skip to content

Commit

Permalink
implementing ansible support
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeljkoBenovic committed Nov 18, 2023
1 parent e34d25f commit 2ed5779
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 43 additions & 1 deletion aws/ssm/ansible.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,49 @@
package ssm

import (
"github.com/aws/aws-sdk-go/aws"
assm "github.com/aws/aws-sdk-go/service/ssm"
"os"
)

func (s ssm) RunAnsible() error {
s.log.Info("Running ssm ansible command")
// TODO: implement

command, err := s.cl.SendCommand(&assm.SendCommandInput{

Check failure on line 12 in aws/ssm/ansible.go

View workflow job for this annotation

GitHub Actions / golangci_lint

command declared and not used (typecheck)
DocumentName: aws.String("AWS-RunAnsiblePlaybook"),
DocumentVersion: aws.String("$LATEST"),
InstanceIds: s.provideInstanceIDs(),
Parameters: s.provideAnsibleCommands(),
TimeoutSeconds: &s.conf.CommandExecMaxWait,
})
if err != nil {
return err
}

s.log.Info("Command deployed successfully")
s.log.Info("Waiting for results")
return nil
}

func (s ssm) provideAnsibleCommands() map[string][]*string {
var resp = map[string][]*string{}
checkStr := "False"

playbookStr, err := os.ReadFile(s.conf.AnsiblePlaybook)
if err != nil {
s.log.Fatalln("Could not read ansible playbook", "err", err.Error())
}
playbook := string(playbookStr)
resp["playbook"] = []*string{&playbook}

if s.conf.AnsibleDryRun {
checkStr = "True"
}
resp["check"] = []*string{&checkStr}

// TODO: implement "ploybookurl" and "extravars"
resp["playbookurl"] = []*string{}
resp["extravars"] = []*string{}

return resp
}
3 changes: 3 additions & 0 deletions conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type Config struct {
BashFile string

AnsiblePlaybook string
AnsibleDryRun bool

AWSProfile string
AWSRegion string
Expand Down Expand Up @@ -56,6 +57,7 @@ func DefaultConfig() Config {
AWSInstanceTags: "",
CommandResultMaxWait: 30,
CommandExecMaxWait: 300,
AnsibleDryRun: false,
}
}

Expand All @@ -71,6 +73,7 @@ func (c *Config) processFlags() {
flag.StringVar(&c.AWSInstanceTags, "tags", c.AWSInstanceTags, "comma delimited list of ec2 tags")
flag.IntVar(&c.CommandResultMaxWait, "max-wait", c.CommandResultMaxWait, "maximum wait time in seconds for command execution")

Check failure on line 74 in conf/conf.go

View workflow job for this annotation

GitHub Actions / golangci_lint

line is 127 characters (lll)
flag.Int64Var(&c.CommandExecMaxWait, "max-exec", c.CommandExecMaxWait, "maximum command execution time in seconds")
flag.BoolVar(&c.AnsibleDryRun, "dry-run", c.AnsibleDryRun, "run ansible in dry-run mode")
flag.Parse()
}

Expand Down

0 comments on commit 2ed5779

Please sign in to comment.