hashicorp / packer-plugin-ansible

Packer plugin for Ansible Provisioner
https://www.packer.io/docs/provisioners/ansible
Mozilla Public License 2.0
47 stars 37 forks source link

ansible provisioner leaves junk in directory called /root/~user #23

Open ghost opened 3 years ago

ghost commented 3 years ago

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


When using the ansible provisioner with either googlecompute, digitalocean or hetzner builders, final images contain an unwanted directory like this:

/root/~user

where "user" is the local user being used to run packer.

As opposed to /root/.ansible, I think this should not happen because it does not happen when using ansible without packer (i.e. using root as the remote user). Because of this, I have to add an extra step to remove the junk.

I also think this is bad because by default the contents of the resulting image should ideally not depend on the user running packer (i.e. it should be as reproducible as possible).

I can reproduce this effect every time as far as I use at least one ansible provisioner in the packer JSON file.

(Not including a minimal JSON to reproduce because this happens always to me, but I will be more than happy to provide one if required).

I'm using packer v1.5.4 from packer_1.5.4_linux_amd64.zip and ansible version 2.7.7+dfsg-1 as distributed by Debian 10.

Thanks.

TheNotary commented 11 months ago

I get this too. I'm using packer from my mac. I just noticed it updates a Library file from my mac as well. I might add the below provisioner to help me out, but am hesitant to add that much code to my packer files.

{
      "type": "shell",
      "inline": [
        "find /home/{{ user {{ `user_name` }} -maxdepth 1 -type d -name "~*" -exec rm -rf {} \;"
      ]
}

Here's the provisioner block I'm using:

{
      "type": "ansible",
      "extra_arguments":  [ "--ssh-extra-args", "-o IdentitiesOnly=yes -o HostKeyAlgorithms=+ssh-rsa -o PubkeyAcceptedAlgorithms=+ssh-rsa", "--scp-extra-args", "'-O'" ],
      "host_alias": "{{user `vm_name`}}",
      "playbook_file": "scripts/ansible/{{user `vm_name`}}.yml",
      "only": ["virtualbox-ovf", "proxmox-clone"]
    }