hashicorp / packer-plugin-ansible

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

packer qemu build with ansible as provisioner fails to connect #11

Open ghost opened 3 years ago

ghost commented 3 years ago

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


Overview of the Issue

I'm using qemu as the builder and ansible as provisioner. The templates will be created from ISO and packer creates a temporary SSH key, which will be used by Ansible to connect. That's not working any longer. First issue: I can see that the generated Key in /temp/ansisible-keyXXXX is empty and second issue: I can't see any difference in "use_proxy:true" or "use_proxy:false".

Reproduction Steps

1: packer build with qemu 2: create a template from ISO where you connect over username / password 3: ansible as provisioner who should use temporary ssh key 4: ansible is unable to connect (permission denied)

Packer version

1.6.6

Simplified Packer Buildfile

{
  "builders": [
    {
      "accelerator": "kvm",
      "boot_command": [
        "<up><tab> inst.text inst.ks=hd:fd0:/CentOS-7-x86_64-cloud.cfg <enter><wait>"
      ],
      "boot_wait": "20s",
      "communicator": "ssh",
      "cpus": 1,
      "disk_interface": "virtio-scsi",
      "disk_size": "20480M",
      "floppy_files": [
        "templates/ks/CentOS/7/CentOS-7-x86_64-cloud.cfg"
      ],
      "format": "qcow2",
      "headless": false,
      "iso_checksum": "{{user `iso_checksum_type`}}:{{user `iso_centos7_checksum`}}",
      "iso_url": "{{user `iso_centos7_url`}}",
      "memory": 2048,
      "net_device": "virtio-net",
      "output_directory": "templates/kvm/centos7/template",
      "shutdown_command": "shutdown --poweroff now",
      "ssh_password": "{{user `vm_root_pw`}}",
      "ssh_timeout": "15m",
      "ssh_username": "root",
      "ssh_clear_authorized_keys": true,
      "type": "qemu",
      "vm_name": "packer_kvm_centos7"
    }
  ],
  "provisioners": [
    {
      "host_alias": "packer-template",
      "playbook_file": "templates/kvm/centos7/playbooks/main.yml",
      "type": "ansible",
      "use_proxy": false,
      "extra_arguments": [ "-vvvv" ]
    },
    {
      "expect_disconnect": true,
      "inline": [
        "reboot"
      ],
      "start_retry_timeout": "30m",
      "type": "shell"
    }
  ]
}

Operating system and Environment details

building machine: fedora 33 with packer 1.6.6 & ansible 2.9.17 building template: CentOS 7 from ISO

Log Fragments and crash.log files

here the logs: https://gist.github.com/Doni7722/666afd5fa7fd364850c0be2835d8d3ae

SwampDragons commented 3 years ago

This is probably related to #6