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

Feature: More control over argument order for ansible provisioner #27

Open
ghost opened this issue Apr 16, 2021 · 0 comments
Open

Feature: More control over argument order for ansible provisioner #27

ghost opened this issue Apr 16, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Apr 16, 2021

This issue was originally opened by @duijf as hashicorp/packer#7241. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.


This is a feature request.

Summary: I would like the "command" key for the ansible provisioner to accept lists of strings.

Background: Internally, we have a wrapper around Ansible playbook which ensures that our Ansible playbooks run in the environment they expect. It is responsible for passing the right flags to ansible-playbook for common scenario's, checking preconditions, and some setup. (FWIW, I believe we're not unique in this: I've talked to quite a few people about the way they use Ansible setup and this is quite common from what I've heard)

The wrapper has a subcommand based CLI. So there is our-ansible-wrapper foo, our-ansible-wrapper bar, etc. Because of this, I would like Packer to call our-ansible-wrapper packer-provision PLAYBOOK. This is currently not possible without an intermediate shell script.

What I've tried: This does not work:

{                                                                          
  "type": "ansible",                                                       
  "command": "our-ansible-wrapper packer-provision",
  "playbook_file": "image.yml"                                   
} 

This is because Packer tries to find a binary with a file name of the full command key. So including the space and packer-provision.

Adding packer-provision to extra_arguments also does not work.

{                                                                          
  "type": "ansible",                                                       
  "command": "our-ansible-wrapper",
  "playbook_file": "playbooks/image-base.yml",
  "extra_arguments": [
    "packer-provision"
  ]
}

This is because those extra arguments are appended to the command after other arguments generated by Packer. So packer generates something like our-ansible-wrapper /path/to/playbook -i /tmp/inventory packer-provision.

More control over the order of arguments would be nice.

Request: I would like this to work:

{                                                                          
  "type": "ansible",                                                       
  "command": ["our-ansible-wrapper", "packer-provision"],
  "playbook_file": "playbooks/image-base.yml"
}

I currently work around this by having a separate shell script where the only purpose is to pass that additional argument to our wrapper. I'd prefer not to need it.

This request might generalize to other provisioners, but I haven't tried those yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants