Skip to content

Instantly share code, notes, and snippets.

@gladiatr72
Last active February 26, 2020 20:12
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gladiatr72/74b7c4f30774f1cfb09a to your computer and use it in GitHub Desktop.
Save gladiatr72/74b7c4f30774f1cfb09a to your computer and use it in GitHub Desktop.
IPython - saltstack profile initializers
# similar initializer for minion-side testing
import salt.config
import salt.client
import salt.loader
import salt.utils.minion as Minion_Util
import salt.config
import pprint
pp_ = pprint.PrettyPrinter(indent=4, depth=20)
pp = pp_.pprint
import re, os
caller = salt.client.Caller('/etc/salt/minion')
__opts__ = caller.opts
__opts__['saltenv'] = 'base'
__salt__ = caller.sminion.functions
__pillar__ = __salt__['pillar.items']()
__grains__ = __salt__['grains.items']()
__states__ = caller.sminion.states
__fserver__ = salt.loader.fileserver(__opts__, None)
# this can go in ~/.ipython/profile_salt-master/startup (or ~/.config/ipython/profile_salt-master/startup
# for older versions). It will provide (I think) most of the salt dunders that various and sundry salt
# modules expect to have defined. This provides an alternative for interactive (custom or non-custom) module
# testing without log file sifting.
import salt.config
import salt.client
import salt.loader
import salt.utils.master as Master_Util
import salt.wheel
import salt.config
from salt.pillar import Pillar as Pillar_
import pprint
pp_ = pprint.PrettyPrinter(indent=4, depth=20)
pp = pp_.pprint
import re, os
test_minion = '<minion ID of functional minion goes here>'
__opts__ = salt.config.master_config('/etc/salt/master')
__opts__['test'] = False
saltenv = 'base'
wcaller = salt.wheel.WheelClient(__opts__)
lcaller = salt.client.LocalClient()
__opts__['saltenv'] = 'base'
mutil = Master_Util.MasterPillarUtil(tgt=test_minion, saltenv='base', opts=__opts__)
__pillar__ = mutil.get_minion_pillar()[test_minion]
__grains__ = mutil.get_minion_grains()[test_minion]
__salt__ = salt.loader.minion_mods(__opts__)
__states__ = salt.loader.states(__opts__, None)
__fserver__ = salt.loader.fileserver(__opts__, None)
Pillar = Pillar_(__opts__, __grains__, test_minion, saltenv, functions=__salt__)
top_matches = Pillar.top_matches(Pillar.get_top()[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment