-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ FEATURE ] AddedRun Ansible Playbook functionality (#1)
* added Ansible playbook functionallity * updated readme & cleaned up flags structs
- Loading branch information
1 parent
2c43737
commit c86cab2
Showing
9 changed files
with
398 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package ssm | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/ssm" | ||
) | ||
|
||
type commandType string | ||
|
||
var generateCommand map[commandType]func() *ssm.SendCommandInput | ||
|
||
// these should reflect flag options for -mode flag - bash by default | ||
const ( | ||
bashScript commandType = "bash" | ||
ansiblePlaybook commandType = "ansible" | ||
) | ||
|
||
// prepareCommand sets the function which initializes command based on the flag input | ||
func (a *Adapter) prepareCommand() map[commandType]func() *ssm.SendCommandInput { | ||
generateCommand = map[commandType]func() *ssm.SendCommandInput{ | ||
bashScript: a.runBashScript, | ||
ansiblePlaybook: a.runAnsiblePlaybook, | ||
} | ||
|
||
return generateCommand | ||
} | ||
|
||
// runBashScript initializes AWS-RunShellScript document which will run a bash script on nodes | ||
func (a *Adapter) runBashScript() *ssm.SendCommandInput { | ||
// if we have instance IDs, else if we have tags | ||
if a.instanceIDs != nil { | ||
return &ssm.SendCommandInput{ | ||
DocumentName: aws.String("AWS-RunShellScript"), | ||
DocumentVersion: aws.String("$LATEST"), | ||
InstanceIds: a.instanceIDs, | ||
Parameters: a.commands, | ||
TimeoutSeconds: aws.Int64(300), | ||
} | ||
} else if a.targets != nil { | ||
return &ssm.SendCommandInput{ | ||
DocumentName: aws.String("AWS-RunShellScript"), | ||
DocumentVersion: aws.String("$LATEST"), | ||
Targets: a.targets, | ||
Parameters: a.commands, | ||
TimeoutSeconds: aws.Int64(300), | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (a *Adapter) runAnsiblePlaybook() *ssm.SendCommandInput { | ||
// if we have instance IDs, else if we have tags | ||
if a.instanceIDs != nil { | ||
return &ssm.SendCommandInput{ | ||
DocumentName: aws.String("AWS-RunAnsiblePlaybook"), | ||
DocumentVersion: aws.String("$LATEST"), | ||
InstanceIds: a.instanceIDs, | ||
Parameters: a.commands, | ||
TimeoutSeconds: aws.Int64(300), | ||
} | ||
} else if a.targets != nil { | ||
return &ssm.SendCommandInput{ | ||
DocumentName: aws.String("AWS-RunAnsiblePlaybook"), | ||
DocumentVersion: aws.String("$LATEST"), | ||
Targets: a.targets, | ||
Parameters: a.commands, | ||
TimeoutSeconds: aws.Int64(300), | ||
} | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.