Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Config show for each nodes from Bastion server #7570

Merged
merged 3 commits into from
Nov 25, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 67 additions & 9 deletions components/automate-cli/cmd/chef-automate/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const (
automate-backend-ctl applied --svc=automate-ha-%s
`

GET_FRONTEND_CONFIG = `sudo chef-automate config show`

dateFormat = "%Y%m%d%H%M%S"

postgresql = "postgresql"
Expand All @@ -70,7 +72,16 @@ func init() {
configCmd.AddCommand(patchConfigCmd)
configCmd.AddCommand(setConfigCmd)

showConfigCmd.Flags().BoolVarP(&configCmdFlags.overwriteFile, "overwrite", "o", false, "Overwrite existing config.toml")
showConfigCmd.Flags().BoolVarP(&configCmdFlags.overwriteFile, "overwrite", "O", false, "Overwrite existing config.toml [Standalone]")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.automate, "automate", "a", false, "Shows configurations from Automate node(HA)")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.chef_server, "chef_server", "c", false, "Shows configurations from Chef-server node(HA)")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.postgresql, "postgresql", "p", false, "Shows configurations from PostgresQL node")
showConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.opensearch, "opensearch", "o", false, "Shows configurations from OpenSearch node")
showConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.automate, "a2", false, "Shows configurations from Automate node(HA)[DUPLICATE]")
showConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.chef_server, "cs", false, "Shows configurations from Chef-server node(HA)[DUPLICATE]")
showConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.postgresql, "pg", false, "Shows configurations from PostgresQL node[DUPLICATE]")
showConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.opensearch, "os", false, "Shows configurations from OpenSearch node[DUPLICATE]")

patchConfigCmd.PersistentFlags().BoolVarP(&configCmdFlags.frontend, "frontend", "f", false, "Patch toml configuration to the all frontend nodes")
patchConfigCmd.PersistentFlags().BoolVar(&configCmdFlags.frontend, "fe", false, "Patch toml configuration to the all frontend nodes[DUPLICATE]")

Expand Down Expand Up @@ -99,7 +110,7 @@ var showConfigCmd = &cobra.Command{
Short: "show the Chef Automate configuration",
Long: "Show the Chef Automate configuration. When given a filepath, the output will be written to the file instead of printed to STDOUT",
RunE: runShowCmd,
Args: cobra.RangeArgs(0, 1),
Args: cobra.RangeArgs(0, 2),
}

var patchConfigCmd = &cobra.Command{
Expand All @@ -118,6 +129,59 @@ var setConfigCmd = &cobra.Command{
}

func runShowCmd(cmd *cobra.Command, args []string) error {

if isA2HARBFileExist() {

infra, err := getAutomateHAInfraDetails()
if err != nil {
return err
}

sshUser := infra.Outputs.SSHUser.Value
sskKeyFile := infra.Outputs.SSHKeyFile.Value
sshPort := infra.Outputs.SSHPort.Value

sshConfig := &SSHConfig{
sshUser: sshUser,
sshKeyFile: sskKeyFile,
sshPort: sshPort,
}
sshUtil := NewSSHUtil(sshConfig)

if configCmdFlags.overwriteFile {
writer.Errorln("Overwrite flag is not supported in HA")
}

var scriptCommand string
var hostIpArray []string
switch true {
case configCmdFlags.automate:
hostIpArray = append(hostIpArray, infra.Outputs.AutomatePrivateIps.Value[0])
scriptCommand = GET_FRONTEND_CONFIG
case configCmdFlags.chef_server:
hostIpArray = append(hostIpArray, infra.Outputs.ChefServerPrivateIps.Value[0])
scriptCommand = GET_FRONTEND_CONFIG
case configCmdFlags.postgresql:
hostIpArray = infra.Outputs.PostgresqlPrivateIps.Value
scriptCommand = fmt.Sprintf(GET_CONFIG, "postgresql")
case configCmdFlags.opensearch:
hostIpArray = infra.Outputs.OpensearchPrivateIps.Value
scriptCommand = fmt.Sprintf(GET_CONFIG, "opensearch")
default:
return errors.New("Missing or Unsupported flag\n Please run the following command to see all available flags \n\n`chef-automate config show --help`\n")
}
for i := 0; i < len(hostIpArray); i++ {
sshUtil.getSSHConfig().hostIP = hostIpArray[i]
output, err := sshUtil.connectAndExecuteCommandOnRemote(scriptCommand, true)
if err != nil {
return err
}
writer.Success("Configuration from " + hostIpArray[i] + "node:\n")
writer.Println(output)
}

return nil
}
res, err := client.GetAutomateConfig(configCmdFlags.timeout)
if err != nil {
return err
Expand Down Expand Up @@ -540,17 +604,11 @@ func getConfigForArgsPostgresqlOrOpenSearch(args []string, remoteService string)
}
return dest, nil
}

return nil, nil

}

// isConfigChanged checks if configuration is changed
func isConfigChanged(src interface{}, dest interface{}) bool {
if reflect.DeepEqual(src, dest) {
return false
}
return true
return !reflect.DeepEqual(src, dest)
ArvinthC3000 marked this conversation as resolved.
Show resolved Hide resolved
}

// getExistingAndRequestedConfigForPostgres get requested and existing config for postgresql
Expand Down