-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Ansible provisioner creating directory named after my local user #9118
Comments
Yeah, this is super annoying! 😕 I am seeing the same thing with packer v1.5.6 and ansible 2.9.6. |
What happens if you set https://www.packer.io/docs/provisioners/ansible/#user? |
I can confirm that setting that variable removes the Additionally, there is still a .ansible directory under that remote user's home which is not ideal for machine images. |
The total remediation that I did on this from my end was: diff --git a/build.pkr.hcl b/build.pkr.hcl
index f86b6c4..670a522 100644
--- a/build.pkr.hcl
+++ b/build.pkr.hcl
@@ -5,9 +5,17 @@ build {
provisioner "ansible" {
playbook_file = "./ansible/playbook.yaml"
+ user = "ec2-user"
# extra_arguments = [
# "-vvv"
# ]
}
+
+ # Cleanup after https://github.com/hashicorp/packer/issues/9118
+ provisioner "shell" {
+ inline = [
+ "rm -rf /home/ec2-user/.ansible"
+ ]
+ }
} It's kinda sloppy IMHO, but it seems to get my image up to the standard that I expect. |
The username issue is documented behavior, so it's not something I think we're likely to change, especaily since it will break the behavior for many currently-working configs in a non-obvious way. I think it does make sense to try to clean up the .ansible folder left behind by the ansible provisioner, though -- this would probably be a fairly straightforward first contribution for a community member. I'll open a separate issue for that enhancement. |
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. |
Note: also posted to Stack Overflow in case this is my own stupidity instead of a bug.
Overview of the Issue
While emulating the Packer documentation to perform privileged tasks with the
ansible
provisioner and theamazon-ebs
builder, an unexpected directory gets created.The minimal example below does perform a privileged
apt update
, but it also creates the empty directory/home/ubuntu/~myusername
, wheremyusername
is my local username on my desktop. The directory name does actually contain the tilde.If I try adding
become_user: ubuntu
todiagnose.yml
, the directory does not get created, but Ansible is unable to performapt update
.Reproduction Steps
serverfault_example.json
diagnose.yml
(Note:
ami-085925f297f89fce1
is the current official AMI for Ubuntu 18.04 on an EBS-backed x86 computer in theus-east-1
region.)Packer version
Packer v1.5.5 (running on OSX 10.14.6)
From
packer version
Log Fragments and crash.log files
As written above, Packer runs successfully with no errors. If I add
become_user: ubuntu
todiagnose.yml
, I get the following:The text was updated successfully, but these errors were encountered: