You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When provisioning a LXD container, the current Ansible provisioner fails to make group variables available to the Ansible run.
In debugging this I dumped the Ansible hostvars and saw that there are two hosts defined - a "default" host and a host corresponding to the builder "name" parameter with a "packer-" prefix. The expected group vars are found in the "default" host but not the "packer-" host. Attempting to force the provisioner to use the default host with the ansible-playbook -l option fails because there is no LXD container named "default" available and the host address is set to 127.0.0.1.
Setting the host_alias to 'packer-consulserver' does result in the group vars being available but provisioning fails with can't reach container
The core issue I believe is the generation of the temporary inventory file. The problem is that as part of the creation of the temporary inventory file the ansible_host is set to 127.0.0.1 (hardcoded). I believe this means that for any host which activates the temporary host file the connection settings will be wrong for LXD containers.
As a quick and dirty check I replaced the existing code with the following removing the setting of the ansible_host variable:
This works and I have both group vars available and can access the LXD container.
Summary - my analysis suggests that the hard coding of the ansible_host to 127.0.0.1 when generating the inventory file will cause the provisioner to be unable to successfully connect to the LXD container.
As a final note, I can work around the issue by defining the group variables in the template. This is very non-DRY and hacky.
I think there are at least three issues that need attention here:
The provisioner documentation needs to be updated to describe how to get the provisioner to work with LXD containers. This includes documenting that the container reference is the builder name parameter with a packer- prefix, that the host_alias needs to be set to this concated name and the -l variable (and possible -i) variables need to be set in extra_arguments
The creation of the temporary inventory file needs to be changed so that ansible_host value is set correctly.
Rethinking the temporary host file to allow the user to explicitly set the host file to be used. I might be missing something here, but why shouldn't I be able to pass in one of my existing Ansible hosts files?This would DRY things out
More detail on the debug process can be found in the packer google group discussion: Can't get remote ansible provisioner to assign to existing group during provisioning
This issue was originally opened by @snesbittsea as hashicorp/packer#6052. It was migrated here as a result of the Packer plugin split. The original body of the issue is below.
When provisioning a LXD container, the current Ansible provisioner fails to make group variables available to the Ansible run.
In debugging this I dumped the Ansible hostvars and saw that there are two hosts defined - a "default" host and a host corresponding to the builder "name" parameter with a "packer-" prefix. The expected group vars are found in the "default" host but not the "packer-" host. Attempting to force the provisioner to use the default host with the ansible-playbook -l option fails because there is no LXD container named "default" available and the host address is set to 127.0.0.1.
Setting the host_alias to 'packer-consulserver' does result in the group vars being available but provisioning fails with can't reach container
The core issue I believe is the generation of the temporary inventory file. The problem is that as part of the creation of the temporary inventory file the ansible_host is set to 127.0.0.1 (hardcoded). I believe this means that for any host which activates the temporary host file the connection settings will be wrong for LXD containers.
As a quick and dirty check I replaced the existing code with the following removing the setting of the ansible_host variable:
This works and I have both group vars available and can access the LXD container.
Summary - my analysis suggests that the hard coding of the ansible_host to 127.0.0.1 when generating the inventory file will cause the provisioner to be unable to successfully connect to the LXD container.
As a final note, I can work around the issue by defining the group variables in the template. This is very non-DRY and hacky.
I think there are at least three issues that need attention here:
The provisioner documentation needs to be updated to describe how to get the provisioner to work with LXD containers. This includes documenting that the container reference is the builder name parameter with a packer- prefix, that the host_alias needs to be set to this concated name and the -l variable (and possible -i) variables need to be set in extra_arguments
The creation of the temporary inventory file needs to be changed so that ansible_host value is set correctly.
Rethinking the temporary host file to allow the user to explicitly set the host file to be used. I might be missing something here, but why shouldn't I be able to pass in one of my existing Ansible hosts files?This would DRY things out
Here are my work products:
packer version: 1.2.2-dev
host platform: Ubuntu 17.10
More detail on the debug process can be found in the packer google group discussion: Can't get remote ansible provisioner to assign to existing group during provisioning
packer command:
PACKER_LOG=1 $GOPATH/src/github.com/hashicorp/packer/bin/packer build -debug -only consulserver template.json
packer template:
Playbook:
provisioner.go
provisioner.go.zip
The text was updated successfully, but these errors were encountered: