hashicorp / hashicorp/packer-plugin-ansible
Ansible Can't SSH When SSH Communicator Uses Password
- Dominant language
- Go
- Stars
- 64
- Forks
- 40
- PR merge metrics
- No merged PRs in 30d
Description
_This issue was originally opened by @guybarzi as hashicorp/packer#10639. It was migrated here as a result of the [Packer plugin split](https://github.com/hashicorp/packer/issues/8610#issuecomment-770034737). The original body of the issue is below._
Hi,
I'm trying to provision an Ubuntu 18.04.5 machine with ansible provisioner after building it with vsphere-iso.
However, Ansible can't SSH to the machine, it prompts the following error:
`fatal: [default]: UNREACHABLE! => {"changed": false, "msg": "Failed to connect to the host via ssh: Warning: Permanently added '10.0.0.1' (ECDSA) to the list of known hosts.\r\nLoad key \"/tmp/ansible-key305487509\": invalid format\r\nuser@10.0.0.1: Permission denied (publickey,password).\r\n", "unreachable": true}`
After looking into the problem a little bit, it seems that the problem is that the key file created is empty. I do use the `ssh_password` for the SSH communicator instead of a key file. When I insert `ansible_ssh_pass` as an extra argument for ansible, everything works. However, I think it should work automatically, even with `ssh_password`.
I would appreciate help in fixing this issue or telling me what I did wrong if the problem is on my end.
Here is the configuration associated with the issue:
```hcl
source "vsphere-iso" "ubuntu_18_04_5" {
CPUs = 1
RAM = 1024
boot_command = ["",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"/install/vmlinuz",
" initrd=/install/initrd.gz",
" priority=critical",
" locale=en_US",
" file=/media/preseed.cfg",
""]
boot_order = "disk,cdrom"
cluster = var.cluster
convert_to_template = true
datacenter = var.datacenter
datastore = var.datastore
disk_controller_type = ["pvscsi"]
floppy_files = [var.preseed_path]
folder = var.vm_folder
guest_os_type = "ubuntu64Guest"
host = var.host
insecure_connection = true
iso_checksum = "sha256:8c5fc24894394035402f66f3824beb7234b757dd2b5531379cb310cedfdf0996"
iso_url = "http://cdimage.ubuntu.com/releases/18.04/release/ubuntu-18.04.5-server-amd64.iso"
network_adapters {
network = var.network
network_card = "vmxnet3"
}
storage {
disk_size = "10240"
disk_thin_provisioned = true
}
vcenter_server = var.vcenter
username = var.vcenter_user
password = var.vcenter_password
ssh_username = var.ssh_user
ssh_password = var.ssh_password
vm_name = "Ubuntu_18_04_5-Packer"
notes = "Packer™ Created"
}
build {
sources = ["source.vsphere-iso.ubuntu_18_04_5"]
provisioner "ansible" {
playbook_file = "ubuntu_18_04_5/playbook.yml"
keep_inventory_file = true
use_proxy = false
ansible_env_vars = ["ANSIBLE_HOST_KEY_CHECKING=False"]
}
}
```
Thanks in advance!
Contributor guide
Research direction
Start by reproducing the provided vsphere-iso configuration with ssh_password and the Ansible provisioner, comparing it with the workaround that passes ansible_ssh_pass. Trace how the provisioner handles communicator credentials; done means password-based SSH works without the extra Ansible argument and the empty key-file failure no longer occurs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ansible, go
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100