salt alias

16 views
Skip to first unread message

brad.v...@gmail.com

unread,
Apr 24, 2023, 12:34:48 PM4/24/23
to Salt-users
We are running many kubernetes clusters.  The developers nightly generate a json file with all of the clusters and hosts associated with each cluster which we can pull via curl and parse.  The developers want to be able to target clusters with salt commands.  Up until now, I have had them doing that with:

salt -L $(cluster-info.sh -c <cluster name> | cut -d. -f1 | tr '\n' ',') <whatever salt command>

They want something simpler.  I was trying to define a function:

function sltc () {
  case ${#} in
     1)
         echo "You need at least two parameters to this function"
         ;;
      2)
         salt -L $(cluster-info.sh -c ${1} | cut -d. -f1 | tr '\n' ',')${2}
         ;;
      3)
         salt -L $(cluster-info.sh -c ${1} | cut -d. -f1 | tr '\n' ',')${2} "${3}"
         ;;
  esac
}

Running

sltc CLS1 test.ping

shows a jid, but nothing else.  When I run

salt-run jobs.lookup_jid <jid>

It just displays some warnings, and that is it.  Does anyone have a better idea?

Simon Lundström

unread,
Apr 25, 2023, 5:40:11 AM4/25/23
to salt-...@googlegroups.com
Hey Brad!

Couldn't you add the "cluster info API" as an http_json[1] pillar and then
use pillar targeting[2]?

$ salt -I 'k8scluster:CLS1' test.ping

This way it also works with e.g. salt-api too.

BR,
- Simon

1, https://docs.saltproject.io/en/latest/ref/pillar/all/salt.pillar.http_json.html
2, https://docs.saltproject.io/en/latest/topics/targeting/pillar.html
> --
> You received this message because you are subscribed to the Google Groups "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to salt-users+...@googlegroups.com<mailto:salt-users+...@googlegroups.com>.
> To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/26d11796-46eb-429a-8fa2-ec1548de5ea7n%40googlegroups.com<https://groups.google.com/d/msgid/salt-users/26d11796-46eb-429a-8fa2-ec1548de5ea7n%40googlegroups.com?utm_medium=email&utm_source=footer>.

Brad Van Orden

unread,
Apr 25, 2023, 6:07:00 AM4/25/23
to salt-...@googlegroups.com
We have the clusters in pillars, but for some reason when we get to large clusters, a salt command does not hit them all.  It just seems to arbitrarily pick a sub-set.  Not sure why.  We did see that the -L and comma separated list of servers always seems to work.

You received this message because you are subscribed to a topic in the Google Groups "Salt-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/salt-users/P859PL5_4RY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to salt-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/salt-users/ZEef8JMDiFucokxY%40meow.it.su.se.

brad.v...@gmail.com

unread,
Apr 25, 2023, 7:17:41 AM4/25/23
to Salt-users
Taking salt out of the functions seems to be working.  I switched it to:

function sltc () {
   DRP="$(/root/cluster-info.sh -c ${1} | cut -d. -f1 | tr '\n' ',')"
   echo ${DRP:0:-1}
}

Then call with:

salt -L $(sltc CLS1) cmd.run "grep 'Cipher' /etc/ssh/sshd_config"

and that is working well.  This way, if they make changes to their cluster membership, we don't have to update pillars.  It just gets pulled from the json they publish every night.

Thanks for looking!
Reply all
Reply to author
Forward
0 new messages