Skip to content

Ansible provisioner do not work with ISPW and MACVM #124

@sfc-gh-banowak

Description

@sfc-gh-banowak

Overview of the Issue

Ansible is unable to work with parallels-macvm

Reproduction Steps

  1. Create a simple MacOS VM inside parallels and make sure that ssh auth with password works. Sonoma was used as VM version
  2. Create a packer configuration where you are using Ansible
  3. Provide for builder ssh_username and ssh_password parameters for macvm builder.
  4. Since those two were passed no ssh key is generated.
[ssh_keypair_name](https://developer.hashicorp.com/packer/docs/communicators/ssh#ssh_keypair_name) (string) - If specified, this is the key that will be used for SSH with the machine. The key must match a key pair name loaded up into the remote. By default, this is blank, and Packer will generate a temporary keypair unless [ssh_password](https://developer.hashicorp.com/packer/docs/communicators/ssh#ssh_password) is used. [ssh_private_key_file](https://developer.hashicorp.com/packer/docs/communicators/ssh#ssh_private_key_file) or [ssh_agent_auth](https://developer.hashicorp.com/packer/docs/communicators/ssh#ssh_agent_auth) must be specified when [ssh_keypair_name](https://developer.hashicorp.com/packer/docs/communicators/ssh#ssh_keypair_name) is utilized.
  1. Try to run the Ansible provisioner without proxy.
  2. Read the msg:
    parallels-macvm.macvm_automated: Not using Proxy adapter for Ansible run:
    parallels-macvm.macvm_automated:    Using ssh keys from Packer communicator...
  1. Watch as Ansible is trying to get the SSH key, which is not generated because the password is passed.
==> parallels-macvm.macvm_automated: Executing Ansible: ansible-playbook -e packer_build_name="macvm_automated" -e packer_builder_type=parallels-macvm -e packer_http_addr=0.0.0.0:0 --ssh-extra-args '-o IdentitiesOnly=yes' -vvvv -e ansible_ssh_private_key_file=/var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/ansible-key2040784890 -i /var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/packer-provisioner-ansible1035096009 /Users/banowak/Work/jenkins-macos-ami/images/aws/ansible/main.playbook.yml
  1. Since Ansible requires using SSH keys, which are not generated (empty), observe a connection denial due to an invalid key.
    Log without user passed to ansible:
Trying private key: /var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/ansible-key2040784890\r\nLoad key \"/var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/ansible-key2040784890\": invalid format\r\ndebug2: we did not send a packet, disable method\r\ndebug1: No more authentication methods to try.\r\nec2-user@192.168.64.70: Permission denied (publickey,password,keyboard-interactive).",

Log with user passed to ansible:

/var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/ansible-key1087569498\r\nLoad key \"/var/folders/s4/mcd4dxfn0vz_ssgbz0xnj4xw0000gn/T/ansible-key1087569498\": invalid format\r\ndebug2: we did not send a packet, disable method\r\ndebug1: No more authentication methods to try.\r\nec2-user@192.168.64.70: Permission denied (publickey,password,keyboard-interactive).",

Plugin and Packer version

Packer: 1.9.4
Parallels: 20.1.3
Plugin: 1.2.2

Simplified Packer Buildfile

source "parallels-macvm" "macvm_automated" {
  boot_command     = ["<wait>"]
  boot_wait        = "10s"
  shutdown_command = "sudo shutdown -h now"
  source_path      = "../jenkins_vm/output-sonoma_old/macos-sonoma.macvm"
  ssh_password     = "ec2-user"
  ssh_username     = "ec2-user"
  vm_name          = "macvm_automated_${formatdate("DDMMYYhhmm", timestamp())}"

  prlctl_post = [
    ["status", "{{.Name}}", ]
  ]
}

build {
  sources = ["source.parallels-macvm.macvm_automated"]

  provisioner "ansible" {
    user = "ec2-user"
    playbook_file   = "./../ansible/main.playbook.yml"  
    use_proxy = false # we are using ssh key
    use_sftp = false  # this will use scp instead
    extra_arguments = [ "-vvvv" ] #  "--extra-vars", "ansible_password=ec2-user" 
    ansible_env_vars = [
      "ANSIBLE_CONFIG=./../ansible/ansible.cfg"
    ]
    # ssh_authorized_key_file = "${var.user_home}/.ssh/packer_tmp.pub"
    # ansible_proxy_key_type = "ECDSA"
  }

Operating system and Environment details

Host OS: MacOS 15.2
Hardware: Mac Pro M3

Log Fragments and crash.log files

Possible workarounds

I will try not to shut down the machine and connect to it with a null provisioner.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions