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

extra_arguments in Ansible provisioner not working with multi-line json #10485

Closed
npearson72 opened this issue Jan 14, 2021 · 2 comments
Closed

Comments

@npearson72
Copy link

npearson72 commented Jan 14, 2021

Overview of the Issue

Using multi-line arguments in extra_arguments does not work.

Reproduction Steps

I have the following Ansible provisioner block:

When the --extra-vars arguments are arranged as a single line, all works as expected:

...
    {
      "type": "ansible",
      "playbook_file": "ansible/playbook.yml",
      "extra_arguments": [
        "--extra-vars",
        "ssh_user={{user `ssh_user`}} ssh_port={{user `ssh_port`}} pg_data_dir={{user `pg_data_dir`}}",
        "--tags",
        "{{ user `tags`}}"
      ]
    }
...

When I arrange the --extra-vars as multi-line (valid json syntax), Ansible rejects the command and the script fails to run:

...
  "provisioners": [
    {
      "type": "ansible",
      "playbook_file": "ansible/playbook.yml",
      "extra_arguments": [
        "--extra-vars",
        "ssh_user={{user `ssh_user`}}",
        "ssh_port={{user `ssh_port`}}",
        "pg_data_dir={{user `pg_data_dir`}}",
        "--tags",
        "{{ user `tags`}}"
      ]
    }
  ]
...

Interestingly... the terminal output shows the same input command in both forms. However the second is rejected.

First output (with single line arguments):

==> digitalocean: Executing Ansible: ansible-playbook -e packer_build_name="digitalocean" -e packer_builder_type=digitalocean --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars ssh_user=deployer ssh_port=1111 pg_data_dir=/mnt/pg_data --tags database -e ansible_ssh_private_key_file=/var/folders/jk/_4zr0chs4h13kpkzrfr_gkm40000gn/T/ansible-key233643224 -i /var/folders/jk/_4zr0chs4h13kpkzrfr_gkm40000gn/T/packer-provisioner-ansible381681239 /Users/me/Dev/project/devops/infrastructure/packer/ansible/playbook.yml

Second output (with multi-line arguments):

==> digitalocean: Executing Ansible: ansible-playbook -e packer_build_name="digitalocean" -e packer_builder_type=digitalocean --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars ssh_user=deployer ssh_port=1111 pg_data_dir=/mnt/pg_data --tags database -e ansible_ssh_private_key_file=/var/folders/jk/_4zr0chs4h13kpkzrfr_gkm40000gn/T/ansible-key108274220 -i /var/folders/jk/_4zr0chs4h13kpkzrfr_gkm40000gn/T/packer-provisioner-ansible576775579 /Users/me/Dev/project/devops/infrastructure/packer/ansible/playbook.yml

They appear identical, but second throws a non-zero exit with Ansible complaining that the arguments were not correct.

Packer version

1.6.6

Simplified Packer Buildfile

https://gist.github.com/npearson72/a363b559a72f703905a643d4d4ae0450

Operating system and Environment details

  • MacOS 11.1
  • ansible 2.10.3

Log Fragments and crash.log files

https://gist.github.com/npearson72/b998db9cac3af5a7b1b72692f30b1e3d

@ghost
Copy link

ghost commented Apr 16, 2021

This issue has been automatically migrated to hashicorp/packer-plugin-ansible#9 because it looks like an issue with that plugin. If you believe this is not an issue with the plugin, please reply to hashicorp/packer-plugin-ansible#9.

@ghost
Copy link

ghost commented May 17, 2021

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked as resolved and limited conversation to collaborators May 17, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants