Compare commits
No commits in common. "develop" and "v0.10.2" have entirely different histories.
@ -1,3 +0,0 @@
|
|||||||
kind: Changed
|
|
||||||
body: 'Commands: `host` can now be `localhost` or `127.0.0.1` to run commands locally'
|
|
||||||
time: 2025-03-21T09:08:49.871021144-05:00
|
|
@ -61,8 +61,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsHostLocal(command.Host) {
|
if command.Host != nil {
|
||||||
|
|
||||||
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)
|
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)
|
||||||
if errSSH != nil {
|
if errSSH != nil {
|
||||||
return outputArr, errSSH
|
return outputArr, errSSH
|
||||||
@ -493,10 +492,11 @@ func (cmd *Command) GenerateLogger(opts *ConfigOpts) zerolog.Logger {
|
|||||||
Str("Backy-cmd", cmd.Name).Str("Host", "local machine").
|
Str("Backy-cmd", cmd.Name).Str("Host", "local machine").
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
if !IsHostLocal(cmd.Host) {
|
if cmd.Host != nil {
|
||||||
cmdLogger = opts.Logger.With().
|
cmdLogger = opts.Logger.With().
|
||||||
Str("Backy-cmd", cmd.Name).Str("Host", cmd.Host).
|
Str("Backy-cmd", cmd.Name).Str("Host", *cmd.Host).
|
||||||
Logger()
|
Logger()
|
||||||
|
|
||||||
}
|
}
|
||||||
return cmdLogger
|
return cmdLogger
|
||||||
}
|
}
|
||||||
@ -508,7 +508,7 @@ func (opts *ConfigOpts) ExecCmdsSSH(cmdList []string, hostsList []string) {
|
|||||||
for _, c := range cmdList {
|
for _, c := range cmdList {
|
||||||
cmd := opts.Cmds[c]
|
cmd := opts.Cmds[c]
|
||||||
cmd.RemoteHost = host
|
cmd.RemoteHost = host
|
||||||
cmd.Host = host.Host
|
cmd.Host = &host.Host
|
||||||
opts.Logger.Info().Str("host", h).Str("cmd", c).Send()
|
opts.Logger.Info().Str("host", h).Str("cmd", c).Send()
|
||||||
_, err := cmd.RunCmdSSH(cmd.GenerateLogger(opts), opts)
|
_, err := cmd.RunCmdSSH(cmd.GenerateLogger(opts), opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -541,7 +541,6 @@ func (c *Command) GetVariablesFromConf(opts *ConfigOpts) {
|
|||||||
c.ScriptEnvFile = replaceVarInString(opts.Vars, c.ScriptEnvFile, opts.Logger)
|
c.ScriptEnvFile = replaceVarInString(opts.Vars, c.ScriptEnvFile, opts.Logger)
|
||||||
c.Name = replaceVarInString(opts.Vars, c.Name, opts.Logger)
|
c.Name = replaceVarInString(opts.Vars, c.Name, opts.Logger)
|
||||||
c.OutputFile = replaceVarInString(opts.Vars, c.OutputFile, opts.Logger)
|
c.OutputFile = replaceVarInString(opts.Vars, c.OutputFile, opts.Logger)
|
||||||
c.Host = replaceVarInString(opts.Vars, c.Host, opts.Logger)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// func executeUserCommands() []string {
|
// func executeUserCommands() []string {
|
||||||
|
@ -527,13 +527,13 @@ func processCmds(opts *ConfigOpts) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !IsHostLocal(cmd.Host) {
|
// resolve hosts
|
||||||
|
if cmd.Host != nil {
|
||||||
cmdHost := replaceVarInString(opts.Vars, cmd.Host, opts.Logger)
|
cmdHost := replaceVarInString(opts.Vars, *cmd.Host, opts.Logger)
|
||||||
if cmdHost != cmd.Host {
|
if cmdHost != *cmd.Host {
|
||||||
cmd.Host = cmdHost
|
cmd.Host = &cmdHost
|
||||||
}
|
}
|
||||||
host, hostFound := opts.Hosts[cmd.Host]
|
host, hostFound := opts.Hosts[*cmd.Host]
|
||||||
if hostFound {
|
if hostFound {
|
||||||
cmd.RemoteHost = host
|
cmd.RemoteHost = host
|
||||||
cmd.RemoteHost.Host = host.Host
|
cmd.RemoteHost.Host = host.Host
|
||||||
@ -541,12 +541,12 @@ func processCmds(opts *ConfigOpts) error {
|
|||||||
cmd.RemoteHost.HostName = host.HostName
|
cmd.RemoteHost.HostName = host.HostName
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
opts.Logger.Info().Msgf("adding host %s to host list", cmd.Host)
|
opts.Logger.Info().Msgf("adding host %s to host list", *cmd.Host)
|
||||||
if opts.Hosts == nil {
|
if opts.Hosts == nil {
|
||||||
opts.Hosts = make(map[string]*Host)
|
opts.Hosts = make(map[string]*Host)
|
||||||
}
|
}
|
||||||
opts.Hosts[cmd.Host] = &Host{Host: cmd.Host}
|
opts.Hosts[*cmd.Host] = &Host{Host: *cmd.Host}
|
||||||
cmd.RemoteHost = &Host{Host: cmd.Host}
|
cmd.RemoteHost = &Host{Host: *cmd.Host}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@ -607,10 +607,8 @@ func processCmds(opts *ConfigOpts) error {
|
|||||||
opts.Logger.Debug().Msg("changing password for user: " + cmd.Username)
|
opts.Logger.Debug().Msg("changing password for user: " + cmd.Username)
|
||||||
cmd.UserPassword = getExternalConfigDirectiveValue(cmd.UserPassword, opts)
|
cmd.UserPassword = getExternalConfigDirectiveValue(cmd.UserPassword, opts)
|
||||||
}
|
}
|
||||||
|
if cmd.Host != nil {
|
||||||
if !IsHostLocal(cmd.Host) {
|
host, ok := opts.Hosts[*cmd.Host]
|
||||||
|
|
||||||
host, ok := opts.Hosts[cmd.Host]
|
|
||||||
if ok {
|
if ok {
|
||||||
cmd.userMan, err = usermanager.NewUserManager(host.OS)
|
cmd.userMan, err = usermanager.NewUserManager(host.OS)
|
||||||
}
|
}
|
||||||
@ -679,9 +677,7 @@ func processHooks(cmd *Command, hooks []string, opts *ConfigOpts, hookType strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
func detectOSType(cmd *Command, opts *ConfigOpts) error {
|
func detectOSType(cmd *Command, opts *ConfigOpts) error {
|
||||||
|
if cmd.Host == nil {
|
||||||
if IsHostLocal(cmd.Host) {
|
|
||||||
|
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
cmd.OS = "linux"
|
cmd.OS = "linux"
|
||||||
opts.Logger.Info().Msg("Unix/Linux type OS detected")
|
opts.Logger.Info().Msg("Unix/Linux type OS detected")
|
||||||
@ -690,7 +686,7 @@ func detectOSType(cmd *Command, opts *ConfigOpts) error {
|
|||||||
return fmt.Errorf("using an os that is not yet supported for user commands")
|
return fmt.Errorf("using an os that is not yet supported for user commands")
|
||||||
}
|
}
|
||||||
|
|
||||||
host, ok := opts.Hosts[cmd.Host]
|
host, ok := opts.Hosts[*cmd.Host]
|
||||||
if ok {
|
if ok {
|
||||||
if host.OS != "" {
|
if host.OS != "" {
|
||||||
return nil
|
return nil
|
||||||
|
@ -46,9 +46,9 @@ func (opts *ConfigOpts) ListCommand(cmd string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// is it remote or local
|
// is it remote or local
|
||||||
if !IsHostLocal(cmdInfo.Host) {
|
if cmdInfo.Host != nil {
|
||||||
println()
|
println()
|
||||||
print("Host: ", cmdInfo.Host)
|
print("Host: ", *cmdInfo.Host)
|
||||||
println()
|
println()
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -441,8 +441,8 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
|
|||||||
|
|
||||||
cmdCtxLogger.Info().
|
cmdCtxLogger.Info().
|
||||||
Str("Command", command.Name).
|
Str("Command", command.Name).
|
||||||
Str("Host", command.Host).
|
Str("Host", *command.Host).
|
||||||
Msgf("Running %s on host %s", getCommandTypeAndSetCommandInfoLabel(command.Type), command.Host)
|
Msgf("Running %s on host %s", getCommandTypeAndSetCommandInfoLabel(command.Type), *command.Host)
|
||||||
|
|
||||||
// cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
|
// cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
|
||||||
|
|
||||||
@ -811,8 +811,3 @@ func CheckIfHostHasHostName(host string) (bool, string) {
|
|||||||
println(HostName)
|
println(HostName)
|
||||||
return HostName != "", HostName
|
return HostName != "", HostName
|
||||||
}
|
}
|
||||||
|
|
||||||
func IsHostLocal(host string) bool {
|
|
||||||
host = strings.ToLower(host)
|
|
||||||
return host == "127.0.0.1" || host == "localhost" || host == ""
|
|
||||||
}
|
|
||||||
|
@ -56,7 +56,7 @@ type (
|
|||||||
// See CommandType enum further down the page for acceptable values
|
// See CommandType enum further down the page for acceptable values
|
||||||
Type CommandType `yaml:"type,omitempty"`
|
Type CommandType `yaml:"type,omitempty"`
|
||||||
|
|
||||||
Host string `yaml:"host,omitempty"`
|
Host *string `yaml:"host,omitempty"`
|
||||||
|
|
||||||
Hooks *Hooks `yaml:"hooks,omitempty"`
|
Hooks *Hooks `yaml:"hooks,omitempty"`
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user