NixOS / nixops

NixOps is a tool for deploying to NixOS machines in a network or cloud.
https://nixos.org/nixops
GNU Lesser General Public License v3.0
1.78k stars 365 forks source link

unable to start SSH master connection on virtualbox #1403

Open tobiasBora opened 3 years ago

tobiasBora commented 3 years ago

I don't know why, but the very first time I tried nixops on a simple configuration it worked, but now I get the following errors:

ssh: Could not resolve hostname services: Name or service not known
services....> could not connect to ‘root@services’, retrying in 1 seconds...
[...]
nixops.ssh_util.SSHConnectionFailed: unable to start SSH master connection to ‘root@services’

Here are the full logs, with all relevant files. Also, let me know if you know how to give alternative hosts, like gitea.example.org to the VM (useful for testing).

[me@me:/tmp/nixops]$ cat trivial.nix 
{
  network.description = "Web server";

  giteabackend =
    { config, pkgs, ... }:
    { networking.firewall.allowedTCPPorts = [ 80 ];
      ## Install gitea
      services.gitea = {
        enable = true;
        database = {
          type = "postgres";
          password = "hello";
        };
        domain = "giteabackend";
        rootUrl = "https://giteabackend/";
        httpPort = 8080;
        # https://github.com/go-gitea/gitea/blob/master/custom/conf/app.ini.sample
        extraConfig =
          ''
            [service]
            DISABLE_REGISTRATION = true
          '';
      };
      ## Setup nginx for gitea
      services.nginx = {
        enable = true;
        virtualHosts = {
          "giteabackend" = {
            locations."/" = {
              proxyPass = "http://localhost:8080/";
            };
          };
        };
      };
    };
  services.postgresql = {
    enable = true;
  };
}

[me@me:/tmp/nixops]$ cat trivial-vbox.nix 
{
  giteabackend =
    { config, pkgs, ... }:
    { deployment.targetEnv = "virtualbox";
      deployment.virtualbox.memorySize = 1024; # megabytes
      deployment.virtualbox.vcpu = 2; # number of cpus
    };
}

[me@me:/tmp/nixops]$ nixops create ./trivial.nix ./trivial-vbox.nix -d mygitea
created deployment ‘504bb202-f848-11ea-8a8f-024299f3f712’
504bb202-f848-11ea-8a8f-024299f3f712

[me@me:/tmp/nixops]$ nixops info -d mygitea
trace: warning: types.string is deprecated because it quietly concatenates strings
Network name: mygitea
Network UUID: 504bb202-f848-11ea-8a8f-024299f3f712
Network description: Web server
Nix expressions: /tmp/nixops/trivial.nix /tmp/nixops/trivial-vbox.nix

+--------------+---------+------------+-------------+------------+
| Name         |  Status | Type       | Resource Id | IP address |
+--------------+---------+------------+-------------+------------+
| services     | Missing | none       |             |            |
| giteabackend | Missing | virtualbox |             |            |
+--------------+---------+------------+-------------+------------+

[me@me:/tmp/nixops]$ nixops deploy -d mygitea
trace: warning: types.string is deprecated because it quietly concatenates strings
services....> generating new SSH keypair... 
giteabackend> creating VirtualBox VM...
services....> done
ssh: Could not resolve hostname services: Name or service not known
services....> could not connect to ‘root@services’, retrying in 1 seconds...
giteabackend> Virtual machine 'nixops-504bb202-f848-11ea-8a8f-024299f3f712-giteabackend' is created and registered.
giteabackend> UUID: fe9dd12d-8951-4a10-a96d-6378304f63b8
giteabackend> Settings file: '/home/me/VirtualBox VMs/nixops-504bb202-f848-11ea-8a8f-024299f3f712-giteabackend/nixops-504bb202-f848-11ea-8a8f-024299f3f712-giteabackend.vbox'
giteabackend> creating disk ‘disk1’...
ssh: Could not resolve hostname services: Name or service not known
services....> could not connect to ‘root@services’, retrying in 2 seconds...
giteabackend> 0%...ssh: Could not resolve hostname services: Name or service not known

services....> could not connect to ‘root@services’, retrying in 4 seconds...
giteabackend> 10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
giteabackend> Clone medium created in format 'VDI'. UUID: 2a3ed944-8aca-4279-b0a8-7f77891d6475
giteabackend> attaching disk ‘disk1’...
ssh: Could not resolve hostname services: Name or service not known
services....> could not connect to ‘root@services’, retrying in 8 seconds...
giteabackend> Waiting for VM "nixops-504bb202-f848-11ea-8a8f-024299f3f712-giteabackend" to power on...
giteabackend> VM "nixops-504bb202-f848-11ea-8a8f-024299f3f712-giteabackend" has been successfully started.
giteabackend> waiting for IP address........ssh: Could not resolve hostname services: Name or service not known
................................ 192.168.56.104
giteabackend> setting state version to 19.03
giteabackend> waiting for SSH...
Traceback (most recent call last):
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/bin/..nixops-wrapped-wrapped", line 991, in <module>
    args.op()
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/bin/..nixops-wrapped-wrapped", line 412, in op_deploy
    max_concurrent_activate=args.max_concurrent_activate)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/deployment.py", line 1063, in deploy
    self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/deployment.py", line 1052, in run_with_notify
    f()
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/deployment.py", line 1063, in <lambda>
    self.run_with_notify('deploy', lambda: self._deploy(**kwargs))
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/deployment.py", line 996, in _deploy
    nixops.parallel.run_tasks(nr_workers=-1, tasks=self.active_resources.itervalues(), worker_fun=worker)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/parallel.py", line 44, in thread_fun
    result_queue.put((worker_fun(t), None, t.name))
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/deployment.py", line 979, in worker
    os_release = r.run_command("cat /etc/os-release", capture_stdout=True)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/backends/__init__.py", line 337, in run_command
    return self.ssh.run_command(command, self.get_ssh_flags(), **kwargs)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/ssh_util.py", line 280, in run_command
    master = self.get_master(flags, timeout, user)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/ssh_util.py", line 200, in get_master
    compress=self._compress)
  File "/nix/store/5cqj6sjb7i4hklfrqllvpf30i1650l66-nixops-1.7/lib/python2.7/site-packages/nixops/ssh_util.py", line 57, in __init__
    "‘{0}’".format(target)
nixops.ssh_util.SSHConnectionFailed: unable to start SSH master connection to ‘root@services’
chrisportela commented 3 years ago

I'm having the same issue trying to start a machine on Mojave using the trivial-vbox.nix example.

tewfik-ghariani commented 3 years ago

I believe the issue is very specific to your example and not related to nixops SSH function

If you look closely at the code, you'll see that you are actually creating a different resource called services and all of the SSH errors are related to that resource

| services     | Missing | none       |             |            |

Reason being, you have placed the 'services.postgresql' definition outside of the main "giteabackend" bloc thus making it seem as a different machine

      };
    };
  services.postgresql = {
    enable = true;
  };
}

So to fix this, ,you just have to move one of the closing curly braces written before the 'services.postgresql' to just after it

Hope this may help!