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

Ansible provisioner unable to SSH when run by Packer, but runs successfully when run manually using the same args as Packer. #49

Open
eric-gunn opened this issue Jun 9, 2021 · 1 comment

Comments

@eric-gunn
Copy link

Overview of the Issue

Ansible provisioner fails when run by Packer, runs successfully on its own. Same environment, same hosts, same inventory, same vars.

Reproduction Steps

  1. Run packer build -on-error ask -force -var-file kali-repo/packer/2021.1.json kali-repo/packer/kali-base.json
  2. run the exact ansible-playbook command Packer specifies in the output. It'll run without fail:

asciicast

Packer version

1.7.2

Simplified Packer Buildfile

Provisiner setup:

...
"provisioners": [
    {
      "type": "ansible",
      "user": "kali",
      "use_proxy": false,
      "keep_inventory_file": true,
      "playbook_file": "kali-repo/ansible/base-playbook.yml",
      "extra_arguments": [
        "--extra-vars",
        "\"ansible_user=kali ansible_password=kali ansible_sudo_pass=kali ansible_become_method=sudo ansible_become_user=root ansible_host={{ build `Host` }} ansible_port=22 ansible_ssh_common_args='-o StrictHostKeyChecking=no' ansible_password=kali\""
      ],
      "ansible_env_vars": [
        "ANSIBLE_HOST_KEY_CHECKING=False"
      ]
    }
  ],
...

Operating system and Environment details

64 bit Alpine Linux container

Log Fragments and crash.log files

Packer:

==> vsphere-clone: Provisioning with Ansible...
    vsphere-clone: Not using Proxy adapter for Ansible run:
    vsphere-clone:      Using ssh keys from Packer communicator...
==> vsphere-clone: Executing Ansible: ansible-playbook -e packer_build_name="vsphere-clone" -e packer_builder_type=vsphere-clone -e packer_http_addr=10.80.0.18:0 --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars "ansible_user=kali ansible_password=kali ansible_sudo_pass=kali ansible_become_method=sudo ansible_become_user=root ansible_host=172.16.50.19 ansible_port=22 ansible_ssh_common_args='-o StrictHostKeyChecking=no' ansible_password=kali" -e ansible_ssh_private_key_file=/tmp/ansible-key061932775 -i /tmp/packer-provisioner-ansible235206426 /tmp/build/put/kali-repo/ansible/base-playbook.yml
    vsphere-clone:
    vsphere-clone: PLAY [configure Kali base] *****************************************************
    vsphere-clone:
    vsphere-clone: TASK [Gathering Facts] *********************************************************
    vsphere-clone: fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '172.16.50.19' (ECDSA) to the list of known hosts.\r\nLoad key \"/tmp/ansible-key061932775\": invalid format\r\nkali@172.16.50.19: Permission denied (publickey,password).", "unreachable": true}
    vsphere-clone:      to retry, use: --limit @/tmp/build/put/kali-repo/ansible/base-playbook.retry
    vsphere-clone:
    vsphere-clone: PLAY RECAP *********************************************************************
    vsphere-clone: default                    : ok=0    changed=0    unreachable=1    failed=0
    vsphere-clone:
==> vsphere-clone: Error executing Ansible: Non-zero exit status: exit status 4

Ansible:

ansible-playbook -e packer_build_name="vsphere-clone" -e packer_builder_type=vsphere-clone -e packer_http_addr=10.80.0.18:0 --ssh-extra-args '-o IdentitiesOnly=yes' --extra-vars "ansible_user=kali ansible_password=kali ansible_sudo_pass=kali ansible_bec
ome_method=sudo ansible_become_user=root ansible_host=172.16.50.19 ansible_port=22 ansible_ssh_common_args='-o StrictHostKeyChecking=no' ansible_password=kali" -e ansible_ssh_private_key_file=/tmp/ansible-key061932775 -i /tmp/packer-provisioner-ansible235206426 /tmp/bui
ld/put/kali-repo/ansible/base-playbook.yml

PLAY [configure Kali base] ***************************************************************************************************************************************************************************************************************************************************

TASK [Gathering Facts] *******************************************************************************************************************************************************************************************************************************************************
 [WARNING]: Module invocation had junk after the JSON data: AttributeError("module 'platform' has no attribute 'dist'") KeyError('ansible_os_family')

ok: [default]

TASK [Pause for 1 minute] ****************************************************************************************************************************************************************************************************************************************************
Pausing for 5 seconds
(ctrl+C then 'C' = continue early, ctrl+C then 'A' = abort)
ok: [default]

TASK [Install xrdp] **********************************************************************************************************************************************************************************************************************************************************
changed: [default]
@nywilken nywilken transferred this issue from hashicorp/packer Jun 9, 2021
@SwampDragons
Copy link
Contributor

Reading over the issues right now, this is probably a duplicate of #6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants