Last active
February 26, 2020 20:12
-
-
Save gladiatr72/74b7c4f30774f1cfb09a to your computer and use it in GitHub Desktop.
IPython - saltstack profile initializers
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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