Skip to content

Commit

Permalink
Add support for Bolt plan and module path option
Browse files Browse the repository at this point in the history
  • Loading branch information
martezr committed Jul 22, 2019
1 parent ca05139 commit 764af88
Show file tree
Hide file tree
Showing 3 changed files with 207 additions and 5 deletions.
34 changes: 31 additions & 3 deletions bolt/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ type Config struct {
// The bolt task to execute.
BoltTask string `mapstructure:"bolt_task"`

// The bolt plan to execute.
BoltPlan string `mapstructure:"bolt_plan"`

// The bolt module path
BoltModulePath string `mapstructure:"bolt_module_path"`

// The optional inventory file
InventoryFile string `mapstructure:"inventory_file"`
LocalPort int `mapstructure:"local_port"`
LocalPort int `mapstructure:"local_port"`

User string `mapstructure:"user"`
User string `mapstructure:"user"`
SSHHostKeyFile string `mapstructure:"ssh_host_key_file"`
SSHAuthorizedKeyFile string `mapstructure:"ssh_authorized_key_file"`
}
Expand Down Expand Up @@ -207,10 +213,32 @@ func (p *Provisioner) Cancel() {
func (p *Provisioner) executeBolt(ui packer.Ui, comm packer.Communicator, privKeyFile string) error {
// inventory := p.config.InventoryFile
bolttask := p.config.BoltTask
boltplan := p.config.BoltPlan
boltmodulepath := p.config.BoltModulePath

// var envvars []string
target := "ssh://127.0.0.1:" + strconv.Itoa(p.config.LocalPort)
args := []string{"task", "run", bolttask, "--nodes", target, "--no-host-key-check", "--user", p.config.User, "--private-key", privKeyFile }
var boltcommand string
if p.config.BoltTask != "" {
boltcommand = "task"
} else {
boltcommand = "plan"
}
args := []string{boltcommand, "run"}
if p.config.BoltTask != "" {
args = append(args, bolttask)
} else {
args = append(args, boltplan)
}

if p.config.BoltModulePath != "" {
args = append(args, "--modulepath", boltmodulepath)
}

args = append(args, "--nodes", target)
args = append(args, "--no-host-key-check")
args = append(args, "--user", p.config.User)
args = append(args, "--private-key", privKeyFile)
// if len(privKeyFile) > 0 {
// Changed this from using --private-key to supplying -e bolt_ssh_private_key_file as the latter
// is treated as a highest priority variable, and thus prevents overriding by dynamic variables
Expand Down
8 changes: 6 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
module github.com/martezr/packer-provisioner-puppet-bolt

require (
github.com/hashicorp/packer v1.4.0
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999 // indirect
github.com/denverdino/aliyungo v0.0.0-20190220033614-36e2ae938978 // indirect
github.com/hashicorp/packer v1.4.2
github.com/kisielk/gotool v1.0.0 // indirect
github.com/xanzy/go-cloudstack v2.4.1+incompatible // indirect
golang.org/x/crypto v0.0.0-20190424203555-c05e17bb3b2d
)
Loading

0 comments on commit 764af88

Please sign in to comment.