From: Simon Ruderich <simon@ruderich.org>
Date: Mon, 17 May 2021 06:37:23 +0000 (+0200)
Subject: config: config.yaml: add global "ssh_user" option
X-Git-Url: https://ruderich.org/simon/gitweb/?a=commitdiff_plain;h=783a6fe604cdedeb386e9abad59b7d87d0d119e0;p=safcm%2Fsafcm.git

config: config.yaml: add global "ssh_user" option

This option is used as default value when the host option "ssh_user" is
empty. Like the host option it defaults to an empty value which tells
`ssh` to use the current user.
---

diff --git a/cmd/safcm/config/config.go b/cmd/safcm/config/config.go
index fafa791..74f486e 100644
--- a/cmd/safcm/config/config.go
+++ b/cmd/safcm/config/config.go
@@ -34,6 +34,8 @@ type Config struct {
 
 	DetectGroups  []string `yaml:"detect_groups"`
 	GroupPriority []string `yaml:"group_priority"`
+
+	SshUser string `yaml:"ssh_user"`
 }
 
 func LoadConfig() (*Config, error) {
diff --git a/cmd/safcm/sync.go b/cmd/safcm/sync.go
index 0f7c54f..6f38daf 100644
--- a/cmd/safcm/sync.go
+++ b/cmd/safcm/sync.go
@@ -370,7 +370,11 @@ func (s *Sync) Host(wg *sync.WaitGroup) error {
 	}()
 
 	// Connect to remote host
-	err := conn.DialSSH(s.host.SshUser, s.host.Name, s.config.SshConfig)
+	user := s.host.SshUser
+	if user == "" {
+		user = s.config.SshUser
+	}
+	err := conn.DialSSH(user, s.host.Name, s.config.SshConfig)
 	if err != nil {
 		return err
 	}