Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set packer_http_addr of extra-vars as an empty string when it's nil #174

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion provisioner/ansible-local/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -549,8 +549,12 @@ func (p *Provisioner) invokeGalaxyCommand(args []string, ui packersdk.Ui, comm p
func (p *Provisioner) executeAnsible(ui packersdk.Ui, comm packersdk.Communicator) error {
inventory := filepath.ToSlash(filepath.Join(p.config.StagingDir, filepath.Base(p.config.InventoryFile)))

packerHTTPAddr := p.generatedData["PackerHTTPAddr"]
if packerHTTPAddr == nil {
packerHTTPAddr = ""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest maybe not adding the value to the extra-vars instead?
Unless this is used in the target, but then I would assume that it being empty would probably yield an error, so it may or may not be a good idea, what do you think?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your reply and suggestion. Your idea is better. The ansible-playbook already provides a good handler for empty/default extra-vars, so I believe there will be no potential error. It's unnecessary to add them explicitly when they are empty.

I'm testing new codes with my module. Then I'll update this patch once I get any updates.

}
extraArgs := fmt.Sprintf(" --extra-vars \"packer_build_name=%s packer_builder_type=%s packer_http_addr=%s -o IdentitiesOnly=yes\" ",
p.config.PackerBuildName, p.config.PackerBuilderType, p.generatedData["PackerHTTPAddr"])
p.config.PackerBuildName, p.config.PackerBuilderType, packerHTTPAddr)
if len(p.config.ExtraArguments) > 0 {
extraArgs = extraArgs + strings.Join(p.config.ExtraArguments, " ")
}
Expand Down