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 #9

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

Comments

@ghost
Copy link

ghost commented Apr 16, 2021

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


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

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