gyptazy / vagrant-arm64-boxes

Collection of Vagrant Boxes for ARM64 (Apple Silicon support)
https://gyptazy.ch/blog/collection-of-vagrant-boxes-images-for-apple-silicon-based-on-arm64/
5 stars 0 forks source link

vm on oracle8.8 linux is not able to start properly due to missing passwordless sudo for vagrant user #3

Open oleksandr-shalbanov-fntext opened 1 year ago

oleksandr-shalbanov-fntext commented 1 year ago

During vagrant up getting following error:

==> database: Setting hostname...
The following SSH command responded with a non-zero exit status.
Vagrant assumes that this means the command failed!

# Update sysconfig
if [ -f /etc/sysconfig/network ]; then
  sed -i 's/\(HOSTNAME=\).*/\1database/' /etc/sysconfig/network
fi
# Update DNS
  1 #=============================================================
find /etc/sysconfig/network-scripts -maxdepth 1 -type f -name 'ifcfg-*' | xargs -r sed -i 's/\(DHCP_HOSTNAME=\).*/\1"database"/'
# Set the hostname - use hostnamectl if available
echo 'database' > /etc/hostname

Stdout from the command:

Stderr from the command:

Vagrant file:

#=============================================================
#-----------------------Configuration-------------------------
#=============================================================

hosts = {
    'artifactory' => {
        'addr'  => '192.168.56.121', 
        'mem'   => 3072, 
        'cpus'  => 2, 
        'image' => "gyptazy/oraclelinux8.8-arm64"},
    'containerregistry' => {
        'addr'  => '192.168.56.122', 
        'mem'   => 3072, 
        'cpus'  => 2, 
        'image' => "gyptazy/oraclelinux8.8-arm64"},
    'database' => {
        'addr'  => '192.168.56.123', 
        'mem'   => 3072, 
        'cpus'  => 2, 
        'image' => "gyptazy/oraclelinux8.8-arm64"}
}
#vagrant_stuff    = '/Users/brenner/vagrant'
#source_mount     = vagrant_stuff
#dest_mount       = '/vagrant'

#=============================================================
#---------------------------Code------------------------------
#=============================================================

Vagrant.configure("2") do |config|
#config.vm.synced_folder source_mount, dest_mount 
  hosts.each { |host, params|
    config.vm.define host do |item|
    item.vm.box = params['image']
      item.vm.hostname = host
      #web.vm.box_url = "centos/7"

      item.vm.network :private_network, ip: params['addr']
      item.vm.hostname = host

      item.vm.provider :vmware_desktop do |v|
        v.vmx["memsize"] = params['mem']
        v.vmx["numvcpus"] = params['cpus']
        v.vmx["ssh_info_public"] = true
        v.vmx["ethernet0.pcislotnumber"] = "160"
        #v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
        #v.customize ["modifyvm", :id, "--name", host]
      end
    end
  }
end

Solution: after starting vm do vagrant ssh and run following:

echo "vagrant" | sudo -S chmod u+w /etc/sudoers
sudo  bash -c "echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers"
sudo chmod u-w /etc/sudoers
gyptazy commented 1 year ago

Hey @oleksandr-shalbanov-fntext,

thanks for reporting. Unfortunately, this is indeed a bug due to a missing passwordless sudo configuration with your already mentioned and provided fix. This is covered in #2 and will be fixed in upcoming releases.

Sorry for that.

Cheers, gyptazy

oleksandr-shalbanov-fntext commented 1 year ago

Also I've noticed there is problems with vmware agent: ==> database: Waiting for HGFS to become available... And it never ends.....

twhalsema commented 2 weeks ago

Hello, is there any update on when this will be fixed? It looks like this has been open for about a year. Is there any workaround that can be done in the Vagrantfile before it attempts to change the hostname and hits the error?

gyptazy commented 2 weeks ago

Hey @twhalsema,

unfortunately not before. The only way is to wait until the error occurs, afterwards you can still login to the box with vagrant ssh and use the box as usual and/or adjust the missing sudo config to avoid this behavior.

twhalsema commented 6 days ago

@gyptazy Thanks for the quick reply. I was able to script out what I needed with this workaround. I removed the hostname setting from the Vagrantfile. Then did this:

vagrant up <servername>
vagrant ssh <servername> -c  "echo 'vagrant' | sudo -S sleep 1 && sudo sh -c \"echo 'vagrant ALL=(ALL) NOPASSWD:ALL' > /etc/sudoers.d/vagrant\" && sudo -S hostnamectl set-hostname <desired-hostname>"
gyptazy commented 5 days ago

Happy to hear :) enjoy!