diff --git a/.changelog/17138.txt b/.changelog/17138.txt new file mode 100644 index 00000000000..456e254d5ec --- /dev/null +++ b/.changelog/17138.txt @@ -0,0 +1,3 @@ +```release-note:improvement +cli: Add leader status to output of `nomad server members -json` +``` diff --git a/command/server_members.go b/command/server_members.go index 88db710f22f..3badbc5b4cd 100644 --- a/command/server_members.go +++ b/command/server_members.go @@ -118,7 +118,13 @@ func (c *ServerMembersCommand) Run(args []string) int { // Sort the members sort.Sort(api.AgentMembersNameSort(srvMembers.Members)) + // Determine the leaders per region. + leaders, leaderErr := regionLeaders(client, srvMembers.Members) + if json || len(tmpl) > 0 { + for _, member := range srvMembers.Members { + member.Tags["Leader"] = fmt.Sprintf("%t", isLeader(member, leaders)) + } out, err := Format(json, tmpl, srvMembers.Members) if err != nil { c.Ui.Error(err.Error()) @@ -129,9 +135,6 @@ func (c *ServerMembersCommand) Run(args []string) int { return 0 } - // Determine the leaders per region. - leaders, leaderErr := regionLeaders(client, srvMembers.Members) - // Format the list var out []string if verbose {