0

I'm setting up a Vagrantbox to act as a test-VM for one of my actual physical machines. I'm testing my Ansible scripts there. This works quite well so far.

My Vagrantfile:

# -*- mode: ruby -*-
# vi: set ft=ruby :

IMAGE_NAME = "ubuntu/jammy64" # jammy = 22.04
HOSTNAME = "caprica-test"

VAGRANT_COMMAND = ARGV[0]

Vagrant.configure(2) do |config|
    config.vm.box = IMAGE_NAME
    config.vm.hostname = HOSTNAME
    config.vm.network :private_network, type: "dhcp"

    config.vm.provider "virtualbox" do |v|
        v.memory = 2048
        v.cpus = 2
        v.customize ["modifyvm", :id, "--groups", "/vagrantboxes"]
        v.name = HOSTNAME
    end

    config.vm.provision "ansible" do |ansible|
        ansible.verbose = "v"
        ansible.playbook = "../../../main/workstations/caprica/provision/ansible-playbook.yml"
    end

    # Don't generate SSH keys -> don't override the keys provisioned by ansible
    config.ssh.insert_key = false
    config.ssh.private_key_path = ["~/.vagrant.d/insecure_private_key", "~/.ssh/id_rsa"]

    # provision box as user "vagrant", but connect as different user (when running `vagrant ssh`)
    if VAGRANT_COMMAND == "ssh"
        config.ssh.username = 'starbuck'
    end
end

Now I want to verify that my Ansible setup is correct and the way I want it to be. For this I wanna use Chef InSpec and run some checks after provisioning. My problem is that I can't connect to the Vagrantbox because name resolution does not work.

docker run -it --rm \
    --volume "$HOME/.ssh/known_hosts:/home/starbuck/.ssh/known_hosts:ro" \
    --volume "$SSH_AUTH_SOCK:$SSH_AUTH_SOCK" \
    --volume "$(pwd):$(pwd)" \
    --workdir "$(pwd)" \
    chef/inspec:latest exec inspec-tests --target="ssh://starbuck@caprica-test" --key-files="$HOME/.ssh/id_rsa" --chef-license=accept

I always get connection errors. I mounted the SSH_AUTH_SOCK to make sure the Docker container uses the SSH information and services from my host machine.

I tried a basic ping -c 10 caprica-test (no docker) which results in ping: caprica-test: Temporary failure in name resolution. So I'm rather sure that my host machine cannot resolute the hostname "caprica-test".

I switched the hostname for the IP address and tried to connect again but I always get this error which I don't really understand because vagrant ssh works just fine.

I, [2022-07-05T21:23:39.829959 #1]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]>)
I, [2022-07-05T21:23:40.866179 #1]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]>)
I, [2022-07-05T21:23:41.905142 #1]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]>)
I, [2022-07-05T21:23:42.944189 #1]  INFO -- : [SSH] connection failed, retrying in 1 seconds (#<Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]>)
W, [2022-07-05T21:23:44.005679 #1]  WARN -- : [SSH] connection failed, terminating (#<Net::SSH::AuthenticationFailed: Authentication failed for user [email protected]>)
Transport error, can't connect to 'ssh' backend: SSH session could not be established

Is there a way to add a DNS feature to my Vagrant setup? My host is running Ubuntu 22.04 LTS.

1 Answer 1

0

This isn't really so much an ssh question as it is a question of how to setup a (Ubuntu) local DNS resolver and have vagrant register the VM with the resolver.

Most recent flavors of Ubuntu come with a systemd controlled resolver (systemd-resolved) that also acts as a caching DNS server local to the host.

Alternatively, there are some vagrant-dns plugins that may do what you need.

While not a complete answer, I hope this points you in the right direction.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .