Code Monkey home page Code Monkey logo

Comments (1)

cello86 avatar cello86 commented on September 24, 2024

Hi @jeremymcgee73
I'm using:

packer 1.8.6
ansible 2.15.0

I noticed that from ansible >= 2.8 is required to set use_proxy to false and the ansible-key generated automatically by pakcer ansible provisioner is empty.

I applied this workaround:

packer {
...
  required_plugins {
    sshkey = {
      version = ">= 1.0.9"
      source  = "github.com/ivoronin/sshkey"
    }
  }
}
...
data "sshkey" "install" {
}
...
locals {
...
  data_source_content = {
    "${var.build_kickstart_name}" = templatefile("${abspath(path.root)}/scripts/${var.build_kickstart_name}.pkrtpl.hcl", {
...
      build_ssh_public_key     = data.sshkey.install.public_key
    })
  }
...
}
...
source "vsphere-iso" "rhel" {
...
  communicator         = "ssh"
  ssh_password         = "${var.ssh_password}"
  ssh_private_key_file = data.sshkey.install.private_key_path
...
}
...
build {
  sources = ["source.vsphere-iso.rhel"]

  provisioner "ansible" {
    user              = var.ssh_username
    use_proxy         = false
    groups            = ["all"]
    playbook_file     = "./ansible/test.yaml"
    ansible_env_vars = [
      "ANSIBLE_HOST_KEY_CHECKING=False",
      "ANSIBLE_PYTHON_INTERPRETER=/usr/bin/python3",
      "ANSIBLE_SSH_COMMON_ARGS='-o UserKnownHostsFile=/dev/null'"
    ]
    extra_arguments = [
      "--become"
    ]
  }
...
}

I modified the kickstart file to apply the new public key:

...
sshkey --username=${build_username} "${build_ssh_public_key}"
...
%post
update-crypto-policies --set LEGACY
%end
...

The executed step reported:

==> vsphere-iso.rhel: Executing Ansible: ansible-playbook -e packer_build_name="rhel" -e packer_builder_type=vsphere-iso -e packer_http_addr=127.0.0.1.8888 --ssh-extra-args '-o IdentitiesOnly=yes' --become -e ansible_ssh_private_key_file=/home/test/.cache/packer/ssh_private_key_packer_rsa.pem -i /home/test/.tmp/packer-provisioner-ansible1009054922 /home/test/directory/packer/vsphere-rhel/ansible/test.yaml

from packer-plugin-ansible.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.