Changes to roles_path option

This commit is contained in:
Ruben Tsirunyan 2019-07-27 15:56:14 +04:00
parent d247329599
commit 1b35c586ce
1 changed files with 7 additions and 8 deletions

View File

@ -64,7 +64,7 @@ type Config struct {
GalaxyFile string `mapstructure:"galaxy_file"` GalaxyFile string `mapstructure:"galaxy_file"`
GalaxyCommand string `mapstructure:"galaxy_command"` GalaxyCommand string `mapstructure:"galaxy_command"`
GalaxyForceInstall bool `mapstructure:"galaxy_force_install"` GalaxyForceInstall bool `mapstructure:"galaxy_force_install"`
RolesDir string `mapstructure:"roles_dir"` RolesPath string `mapstructure:"roles_path"`
} }
type Provisioner struct { type Provisioner struct {
@ -108,10 +108,6 @@ func (p *Provisioner) Prepare(raws ...interface{}) error {
p.config.GalaxyCommand = "ansible-galaxy" p.config.GalaxyCommand = "ansible-galaxy"
} }
if p.config.RolesDir == "" {
p.config.RolesDir = "~/.ansible/roles"
}
if p.config.HostAlias == "" { if p.config.HostAlias == "" {
p.config.HostAlias = "default" p.config.HostAlias = "default"
} }
@ -364,15 +360,18 @@ func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.C
} }
func (p *Provisioner) executeGalaxy(ui packer.Ui, comm packer.Communicator) error { func (p *Provisioner) executeGalaxy(ui packer.Ui, comm packer.Communicator) error {
rolesDir := filepath.ToSlash(p.config.RolesDir)
galaxyFile := filepath.ToSlash(p.config.GalaxyFile) galaxyFile := filepath.ToSlash(p.config.GalaxyFile)
// ansible-galaxy install -r requirements.yml -p roles/ // ansible-galaxy install -r requirements.yml
args := []string{"install", "-r", galaxyFile, "-p", rolesDir} args := []string{"install", "-r", galaxyFile}
// Add force to arguments // Add force to arguments
if p.config.GalaxyForceInstall { if p.config.GalaxyForceInstall {
args = append(args, "-f") args = append(args, "-f")
} }
// Add roles_path argument if specified
if p.config.RolesPath != "" {
args = append(args, "-p", filepath.ToSlash(p.config.RolesPath))
}
ui.Message(fmt.Sprintf("Executing Ansible Galaxy")) ui.Message(fmt.Sprintf("Executing Ansible Galaxy"))
cmd := exec.Command(p.config.GalaxyCommand, args...) cmd := exec.Command(p.config.GalaxyCommand, args...)