krebs / krops

Mirror of https://cgit.krebsco.de/krops/about/ (PRs / issues accepted, as can be seen by not having them disabled)
Do What The F*ck You Want To Public License
132 stars 18 forks source link

/etc/hostname workaround #27

Closed leshik closed 3 years ago

leshik commented 3 years ago

Hi,

Is it possible to work around the /etc/hostname file and the HOSTNAME env variable here somehow? I'm deploying from Nix on macOS to the Linux VPS; macOS doesn't have /etc/hostname, and while HOSTNAME is set in the shell, it's not exported. I can work around right now by setting a dummy HOSTNAME, e.g. $(HOSTNAME=localhost nix-build --no-out-link krops.nix), but it would be nice if it were working out of the box.

4z3 commented 3 years ago

Yes, the /etc/hostname file and the HOSTNAME variable are only used to set the default value. Neither of those should be required when explicitly specifying a host in writeDeploy's target attribute, e.g. target = "localhost";. See https://github.com/krebs/krops#target for details.

leshik commented 3 years ago

@4z3 yes, it works this way, but I need to use mkTarget as I want to specify sudo = true. Then it doesn't work.

4z3 commented 3 years ago

Doesn't this work?:

  target = lib.mkTarget "localhost" // {
    sudo = true;
  };
leshik commented 3 years ago

@4z3 no, it doesn't:

error: opening file '/etc/hostname': No such file or directory
(use '--show-trace' to show detailed location information)
4z3 commented 3 years ago

Can you paste/link your krops configuration? I've deleted /etc/hostname locally and unset HOSTNAME, but I cannot reproduce the issue with following snippet:

pkgs.krops.writeDeploy "deploy" {
    source = { /* ... */ };
    target = lib.mkTarget "root@localhost" // {
      extraOptions = [
        "-oLogLevel=DEBUG3"
      ];
    };
  }
4z3 commented 3 years ago

OK, I could reproduce it by using sudo = true;.

4z3 commented 3 years ago

This issue has been addressed in https://github.com/krebs/krops/commit/c2fa48550f2bb46009b9cecdb9ac838dc402ce19, released as v1.24.1. @leshik can you check if this fix works for you?

leshik commented 3 years ago

@4z3 yeah, that works perfectly. Thank you for the quick fix!