From 0a8e4c71862fde8b7250fe8a1bde54a54e479de9 Mon Sep 17 00:00:00 2001 From: renat-sabitov-sirca Date: Sat, 10 May 2014 01:59:05 +1000 Subject: [PATCH] Uploading the whole ansible playbook directory --- provisioner/ansible-local/provisioner.go | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/provisioner/ansible-local/provisioner.go b/provisioner/ansible-local/provisioner.go index 81d86cbd6..861ee8cbc 100644 --- a/provisioner/ansible-local/provisioner.go +++ b/provisioner/ansible-local/provisioner.go @@ -27,6 +27,9 @@ type Config struct { // Path to host_vars directory HostVars string `mapstructure:"host_vars"` + // The playbook dir to upload. + PlaybookDir string `mapstructure:"playbook_dir"` + // The main playbook file to execute. PlaybookFile string `mapstructure:"playbook_file"` @@ -79,6 +82,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { "group_vars": &p.config.GroupVars, "host_vars": &p.config.HostVars, "playbook_file": &p.config.PlaybookFile, + "playbook_dir": &p.config.PlaybookDir, "staging_dir": &p.config.StagingDir, "inventory_file": &p.config.InventoryFile, } @@ -123,6 +127,13 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { } } + // Check that the playbook_dir directory exists, if configured + if len(p.config.PlaybookDir) > 0 { + if err := validateDirConfig(p.config.PlaybookDir, "playbook_dir"); err != nil { + errs = packer.MultiErrorAppend(errs, err) + } + } + // Check that the group_vars directory exists, if configured if len(p.config.GroupVars) > 0 { if err := validateDirConfig(p.config.GroupVars, "group_vars"); err != nil { @@ -158,9 +169,16 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { ui.Say("Provisioning with Ansible...") - ui.Message("Creating Ansible staging directory...") - if err := p.createDir(ui, comm, p.config.StagingDir); err != nil { - return fmt.Errorf("Error creating staging directory: %s", err) + if len(p.config.PlaybookDir) > 0 { + ui.Message("Uploading Playbook directory to Ansible staging directory...") + if err := p.uploadDir(ui, comm, p.config.StagingDir, p.config.PlaybookDir); err != nil { + return fmt.Errorf("Error uploading playbook_dir directory: %s", err) + } + } else { + ui.Message("Creating Ansible staging directory...") + if err := p.createDir(ui, comm, p.config.StagingDir); err != nil { + return fmt.Errorf("Error creating staging directory: %s", err) + } } ui.Message("Uploading main Playbook file...")