Previously, the Ansible provisioner would look for the username from the
`USER` environment variable. Unfortunately, this is not always set -
particularly in Docker containers. It's very confusing to understand why
the error is happening.
Switched to using Go's built-in `os/user` package for retrieving the
current username. @rickard-von-essen had done this in 7369841, but
moved away from it in d59844f because, at the time, it wasn't possible
to use that library with cross-compilation. This was fixed in Go in
795e712b72
Add an `inventory_directory` setting to the Ansible provisioner that
allows a user to specify a directory in which the Packer Ansible
provisioner would write the generated inventory file. If a value is
specified for this setting, then have the Packer Ansible provisioner
pass this directory as the -i arg when it calls ansible.
This would allow an Ansible playbook used by the Packer Ansible
provisioner to use variables specified in `host_vars` and `group_vars`
in this inventory directory.
I've spent 1 hour today debugging why packer does not want to work with
ansible. It turns out `ansible-playbook` command was returning non-zero
exit status because of the file system permission problem.
Output before change:
% packer build rabbitmq.json
amazon-ebs output will be in this color.
1 error(s) occurred:
* exit status 1
Output after change:
amazon-ebs output will be in this color.
1 error(s) occurred:
* Error running "ansible-playbook --version": exit status 1
Add a new option, `use_sftp` to the ansible provisioner. It's default
value is false; ansible provisioner will use SCP by default.
Refactor to consistently set all configure options for ansible
provisioner in the Prepare step.
Remove incorrect information about `ANSIBLE_HOST_KEY_CHECKING=False`
being set when `ansible_env_vars` is not set in the packer template.
Update BATS tests for the ansible provisioner to actually check that the
fetched directory contains the contents expected. This revealed a
problem with the all_options template that required adding a host to the
hosts list in the test playbook.
Ansible may produce very long lines which Scanner can not handle. This
replaces the Scanner with a Reader and uses the ReadString method to
read an arbitrary large line from the ansible-playbook stdout pipe.
Ansible 2.0 deprecated ansible_ssh_user, ansible_ssh_port, ansible_ssh_host
instead use ansible_user, ansible_port, and ansible_host in the
inventory file.
Closes#3275
* Clearly separate host signer and user key generation into separate
functions and data structures.
* Remove inaccurate comment about needing to specify both files if
either one is specified.
* Rename parameters for clarity according to their meaning to the
callee.
* Style the code with gofmt.