Packer error with build from vmx file - "file was not found" - filenotfoundexception

I have a problem that I can't figure out. I'm trying to make my first clone of a VM from Packer (Hashicorp) here is my HCL :
source "vmware-vmx" "basic-example" {
source_path = "D:/HashiCorp/Packer1.8.0/Project/WindowsServer2022.vmx"
vm_name = "Test1"
communicator = "winrm"
winrm_host = "redteam"
winrm_username = "admin"
winrm_password = "Disc0very"
shutdown_command = "shutdown /s"
}
build {
sources = ["sources.vmware-vmx.basic-example"]
}
and when I run my build command I get this result :
D:\HashiCorp\Packer1.8.0\Project>packer build packer_test_win2022CARL.pkr.hcl
vmware-vmx.basic-example: output will be in this color.
==> vmware-vmx.basic-example: Configuring output and export directories...
==> vmware-vmx.basic-example: Creating required virtual machine disks
==> vmware-vmx.basic-example: Cloning source VM...
==> vmware-vmx.basic-example: Deleting output directory...
Build 'vmware-vmx.basic-example' errored after 521 milliseconds 605 microseconds: VMware error: Error: A file was not found
==> Wait completed after 521 milliseconds 605 microseconds
==> Some builds didn't complete successfully and had errors:
--> vmware-vmx.basic-example: VMware error: Error: A file was not found
==> Builds finished but no artifacts were created.

Solved, not enough to point the VMX file, VMware needs other files such as .vmdk, .vmxf etc ... to proceed with the cloning

Related

How do I specify salt version for download in Vagrant to Virtualbox VM?

I am trying to stand up a series of VM's in Virtualbox via Vagrant (Master on Ubuntu 20.04, 7 Minions on Windows Server 2016 and 1 on Windows 10). During the execution of vagrant up I receive the following error on the first VM (Windows Server 2016) after the creation completes and Salt begins to attempt an installation:
==> VM24-APP-OSX-RISK: Checking for guest additions in VM...
==> VM24-APP-OSX-RISK: Setting hostname...
==> VM24-APP-OSX-RISK: Waiting for machine to reboot...
==> VM24-APP-OSX-RISK: Configuring and enabling network interfaces...
==> VM24-APP-OSX-RISK: Running provisioner: salt...
Copying salt minion config to vm.
Uploading minion keys.
Checking if C:\salt\salt-minion.bat is installed
C:\salt\salt-minion.bat was not found.
Checking if C:\salt\salt-call.bat is installed
C:\salt\salt-call.bat was not found.
Using Bootstrap Options: -P -c /tmp -x python3
Bootstrapping Salt... (this may take a while)
Defaulting to minion Python version 2
Service defaulting to run.
**Downloading Salt minion installer Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe
WARNING: Retrying download in 2 seconds. Retry # 1
WARNING: Retrying download in 2 seconds. Retry # 2
WARNING: Retrying download in 2 seconds. Retry # 3
WARNING: Retrying download in 2 seconds. Retry # 4
The request was aborted: Could not create SSL/TLS secure channel.
At C:\tmp\bootstrap_salt.ps1:74 char:5
+ $webclient.DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], WebException
+ FullyQualifiedErrorId : WebException
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ErrorRecord System.Object
The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
The following WinRM command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!
powershell.exe -NonInteractive -NoProfile -executionpolicy bypass -file C:\tmp/bootstrap_salt.ps1 -P -c /tmp -x python3
Stdout from the command:
Defaulting to minion Python version 2
Service defaulting to run.
Downloading Salt minion installer Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe
WARNING: Retrying download in 2 seconds. Retry # 1
WARNING: Retrying download in 2 seconds. Retry # 2
WARNING: Retrying download in 2 seconds. Retry # 3
WARNING: Retrying download in 2 seconds. Retry # 4
The request was aborted: Could not create SSL/TLS secure channel.
At C:\tmp\bootstrap_salt.ps1:74 char:5
+ $webclient.DownloadFile($url, $file)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], WebException
+ FullyQualifiedErrorId : WebException
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True ErrorRecord System.Object
The request was aborted: Could not create SSL/TLS secure channel.
at System.Net.WebClient.DownloadFile(Uri address, String fileName)
at CallSite.Target(Closure , CallSite , Object , Object , Object )
Stderr from the command:
Looking at the installation guide for Salt for Windows (here: https://docs.saltstack.com/en/master/topics/installation/windows.html) - I am pretty sure the issue is that the executable is no longer in the main tree of the older supported builds, but has been moved to the Archive section, effectively breaking the link that I think the installer is trying to run with (Salt-Minion-2018.3.3-Py2-AMD64-Setup.exe). However, I do not see any way to specify the Salt version to use via the Vagrant file, the salt files or anywhere in the code.
Anyone got any ideas?

Vagrant - Deleting old boxes

C:\Users\user\Documents\Code\stores (master -> origin)
λ vagrant box remove --all
Vagrant failed to initialize at a very early stage:
There was an error loading a Vagrantfile. The file being loaded
and the error message are shown below. This is usually caused by
a syntax error.
Path: C:/Users/user/Documents/Code/stores/Vagrantfile
Line number: 0
Message: LoadError: cannot load such file -- C:/Users/user/Documents/Code/stores/vendor/laravel/homestead/scripts/homestead.rb
Hello, I am trying to delete some old boxes. the code no longer exists so vagrant is complaining with the above error. How can I resolve this?
I deleted all the files from C:\Users\user.vagrant.d\boxes

packer image failed during script

I'm trying to build a windows based AMI on AWS with packer and providing the image with powershell script.
For some reason, the build is terminated in the middle of the script and I can't figure the cause since the script is evaluated to run manually.
Here's the part of my PS script where the build ends:
function DownloadFile([Object[]] $sourceFiles, [string]$targetDirectory) {
$wc = New-Object System.Net.WebClient
foreach ($sourceFile in $sourceFiles) {
$sourceFileName = $sourceFile.SubString($sourceFile.LastIndexOf('/') + 1)
$targetFileName = $targetDirectory + $sourceFileName
$wc.DownloadFile($sourceFile, $targetFileName)
Write-Host "Downloaded $sourceFile to file location $targetFileName"
}}
The files are downloaded and then the build stops with the following error:
amazon-ebs: Downloaded File01 to file location D:\file1.exe
amazon-ebs: Downloaded file1 to file location D:\File2.exe
amazon-ebs: Downloaded file3 to file location D:\File3.exe
==> amazon-ebs: Stopping the source instance...
amazon-ebs: Stopping instance, attempt 1
==> amazon-ebs: Waiting for the instance to stop...
==> amazon-ebs: Deregistered AMI PACKER-DEMO-tls, id: ami-3e5a3e51
What can be the cause for the build to stop?

Vagrant box error message

try to download Vagrant box on my mac system and this is the message I get.
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'bahmni-team/bahmni' could not be found. Attempting to find and install...
default: Box Provider: virtualbox
default: Box Version: >= 0
==> default: Loading metadata for box 'bahmni-team/bahmni'
default: URL: https://atlas.hashicorp.com/bahmni-team/bahmni
==> default: Adding box 'bahmni-team/bahmni' (v0.80) for provider: virtualbox
default: Downloading: https://atlas.hashicorp.com/bahmni-team/boxes/bahmni/versions/0.80/providers/virtualbox.box
An error occurred while downloading the remote file. The error
message, if any, is reproduced below. Please fix this error and try
again.
transfer closed with 963850334 bytes remaining to read
how do I resolve this?
After Successful Installing Vagrant box, Got this error
default: Importing base box 'bahmni-team/bahmni'...
Progress: 10%There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.
Command: ["import", "/Users/Paul/.vagrant.d/boxes/bahmni-team-VAGRANTSLASH-bahmni/0.80/virtualbox/box.ovf", "--vsys", "0", "--vmname", "packer-virtualbox-iso-1459089960_1463772163009_23494", "--vsys", "0", "--unit", "7", "--disk", "/Users/Paul/VirtualBox VMs/packer-virtualbox-iso-1459089960_1463772163009_23494/packer-virtualbox-iso-1459089960-disk1.vmdk"]
Stderr: 0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Interpreting /Users/Paul/.vagrant.d/boxes/bahmni-team-VAGRANTSLASH-bahmni/0.80/virtualbox/box.ovf...
OK.
0%...10%...
Progress state: VBOX_E_FILE_ERROR
VBoxManage: error: Appliance import failed
VBoxManage: error: Could not create the imported medium '/Users/Paul/VirtualBox VMs/packer-virtualbox-iso-1459089960_1463772163009_23494/packer-virtualbox-iso-1459089960-disk1.vmdk'.
VBoxManage: error: VMDK: cannot write allocated data block in '/Users/Paul/VirtualBox VMs/packer-virtualbox-iso-1459089960_1463772163009_23494/packer-virtualbox-iso-1459089960-disk1.vmdk' (VERR_DISK_FULL)
VBoxManage: error: Details: code VBOX_E_FILE_ERROR (0x80bb0004), component ApplianceWrap, interface IAppliance
VBoxManage: error: Context: "RTEXITCODE handleImportAppliance(HandlerArg*)" at line 877 of file VBoxManageAppliance.cpp
I think the error "VERR_DISK_FULL" is the error you should focus at. Your disk might have been full. So, solution would be to free some space on the disk and try the command again.
Vagrant is internally using curl and there are issues with curl.
You can try wget on the URL as it usually works better than curl
wget https://atlas.hashicorp.com/bahmni-team/boxes/bahmni/versions/0.80/providers/virtualbox.box
once you have the box file you still need to add to vagrant (vagrant box add bahmni-team/bahmni <path to box file>)

Recipe fails on crete_if_missing

I am following this tutorial: http://www.gotealeaf.com/blog/chef-basics-for-rails-developers , where they have us making our own recipe. The code bellow is the recipe. The problem is with the block of code that starts with cookbook_file "id_rsa" and ends right before the, # Add Github as known host, comment. I was able to get past the cookbook_file "id_rsa" block and the cookbook_file "id_rsa.pub" block by moving my id_rsa and id_rsa.pub files into the rails-stack/files/default/ directory, but now it breaks when it attempts the sudo_without_password block. Surprisingly, if I provision vagrant after every error thrown by the action: create_if_missing blocks the configuration gets as far as the cookbooks_file "authorization keys" block but it gets stuck there; even after provisioning when I get the error the first time. Any ideas about what is happening? Please be as descriptive as you can, I am relatively new to devops and only know a few of the ins and outs of vagrant and chef. Thanks in advance!
execute "apt-get update" do
command "apt-get update"
end
# OS Dendencies
%w(git ruby-dev build-essential libsqlite3-dev libssl-dev).each do |pkg|
package pkg
end
# Deployer user, sudoer and with known RSA keys
user_account 'deployer' do
create_group true
end
group "sudo" do
action :modify
members "deployer"
append true
end
cookbook_file "id_rsa" do
source "id_rsa"
path "/home/deployer/.ssh/id_rsa"
group "deployer"
owner "deployer"
mode 0600
action :create_if_missing
end
cookbook_file "id_rsa.pub" do
source "id_rsa.pub"
path "/home/deployer/.ssh/id_rsa.pub"
group "deployer"
owner "deployer"
mode 0644
action :create_if_missing
end
# Allow sudo command without password for sudoers
cookbook_file "sudo_without_password" do
source "sudo_without_password"
path "/etc/sudoers.d/sudo_without_password"
group "root"
owner "root"
mode 0440
action :create_if_missing
end
# Authorize yourself to connect to server
cookbook_file "authorized_keys" do
source "authorized_keys"
path "/home/deployer/.ssh/authorized_keys"
group "deployer"
owner "deployer"
mode 0600
action :create
end
# Add Github as known host
ssh_known_hosts_entry 'github.com'
# Install Ruby Version
include_recipe 'ruby_build'
ruby_build_ruby '2.1.2'
link "/usr/bin/ruby" do
to "/usr/local/ruby/2.1.2/bin/ruby"
end
gem_package 'bundler' do
options '--no-ri --no-rdoc'
end
# Install Rails Application
include_recipe "runit"
application 'capistrano-first-steps' do
owner 'deployer'
group 'deployer'
path '/var/www/capistrano-first-steps'
repository 'git#github.com:gotealeaf/capistrano-first-steps.git'
rails do
bundler true
database do
adapter "sqlite3"
database "db/production.sqlite3"
end
end
unicorn do
worker_processes 2
end
end
****EDIT*******
Since writing the question the first time, I've commented out the sudo_without_password block and was able to find a work around by adding
ssh_keygen true
to the user_account 'deployer' block.
I also put an empty authorized_keys file in rails-stack/files/default/ and that helps the cookbook_file 'authorized_keys' block run without errors.
Now I get this error when vagrant/chef tries to pull the example repo
==> default: [2014-12-04T22:44:18+00:00] ERROR: deploy_revision[capistrano-first-steps] (/tmp/vagrant-chef-3/chef-solo-2/cookbooks/application/providers/default.rb line 123) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '128'
==> default: ---- Begin output of git ls-remote "git#github.com:gotealeaf/capistrano-first-steps.git" "HEAD" ----
==> default: STDOUT:
==> default: STDERR: Warning: Permanently added the RSA host key for IP address '192.30.252.129' to the list of known hosts.
==> default: Permission denied (publickey).
==> default: fatal: Could not read from remote repository.
==> default:
==> default: Please make sure you have the correct access rights
==> default: and the repository exists.
==> default: ---- End output of git ls-remote "git#github.com:gotealeaf/capistrano-first-steps.git" "HEAD" ----
==> default: Ran git ls-remote "git#github.com:gotealeaf/capistrano-first-steps.git" "HEAD" returned 128
==> default: [2014-12-04T22:44:18+00:00] FATAL: Chef::Exceptions::ChildConvergeError: Chef run process exited unsuccessfully (exit code 1)
The answer is simple, after I remembered I had a similar issue with puppet. For some reason, not sure why using
git#github.com:gotealeaf/capistrano-first-steps.git
Does not sit well with vagrant/chef/puppet. So, what I did was change the above line to
https://github.com/gotealeaf/capistrano-first-steps
and that did it, my config of the box worked and there were no problems!
You probably have to point the application resource to the private key that will be used used to clone the repo.
application 'capistrano-first-steps' do
...
deploy_key lazy { File.read("/home/deployer/.ssh/id_rsa") }
...
end
More info -- https://supermarket.chef.io/cookbooks/application

Resources