Comments (21)
any update on this issue ?
from pepper.
For those interested, I've created the script https://gist.github.com/bbinet/d87bf2571652e4dec68df6b280b2af9d to format pepper output using salt outputters.
It can both format sync and async jobs, and can be used in the following ways:
$ pepper \* state.sls core | pepper_format.py -o highstate
$ pepper --client=local_async \* state.highstate | pepper_format.py
$ pepper_format.py 20170504160400750792
$ pepper_format.py -h
usage: pepper_format.py [-h] [-o OUTPUTTER] [-v] [-p] [-n] [jid]
Format pepper output using any salt outputter
positional arguments:
jid Optional job id
optional arguments:
-h, --help show this help message and exit
-o OUTPUTTER, --outputter OUTPUTTER
Outputter to use
-v, --verbose Verbose output
-p, --profiling Activate profiling
-n, --no-color No color in output
from pepper.
On Ubuntu, if you
"apt install salt-common"
the output modules will be available. It will also default to the format you expect.
from pepper.
Option 2 is to have salt-api run the response through an outputter then send the rendered result back to Pepper.
from pepper.
I think a build-dep would be ok.
Can salt-api already take an outputter option ?
from pepper.
If you specify the Accept
header in your requests salt-api will happily oblige. It would be trivial to add support for Salt's nested outputter and return everything as a giant string. It's possible that color escape codes would even come through unscathed.
from pepper.
Can you think of a way to pipe the json result to do something like :
pepper 'host' state.highstate | salt-call --output highstate --local something
from pepper.
I've failed with
pepper 'host' state.highstate | salt-call --local --output highstate test.outputter
or
salt-call --local --output highstate test.outputter "`pepper 'host' state.highstate `"
from pepper.
Outputter modules are written to run for each minion return, not on the data as a whole. To do this you'd need to write a small Python wrapper script.
from pepper.
Here is a wrapper script that seems to do the job (so far) :
import __builtin__
import sys
import json
import salt.config
from salt.output.highstate import output
__opts__ = salt.config.minion_config('/etc/salt/minion')
__opts__['color']=True
__opts__['state_output_diff'] = True
__opts__['state_verbose'] = False
setattr(__builtin__, '__opts__', __opts__)
print output(json.load(sys.stdin))
from pepper.
it works with highstate dictionnary data, but if you send it the result of a test.ping execution, it truncates the results.
I don't think there is a smart way of selecting the right outputter without further context in the results.
from pepper.
Thanks for posting your wrapper. I'm sure others will find that useful.
You're definitely right about not having enough information to decide which outputter to use. Although that information is in the job cache, most (all?) modules don't expose or display it.
from pepper.
The jobs.print_job runner function will output which outputter to use -- which may be helpful but would still require some indirection (run the job async, get the jid, poll for the jid, pipe the result through your wrapper).
from pepper.
+1, being able to use Salt outputters directly from Pepper would be very useful indeed!
@arthurlogilab: I tried a slightly modified version of your python script (customized for running jobs.lookup_jid
runner):
import __builtin__
import subprocess
import sys
import json
import salt.config
from salt.output.highstate import output
__opts__ = salt.config.minion_config('')
__opts__['color']=True
__opts__['state_output_diff'] = True
__opts__['state_verbose'] = False
setattr(__builtin__, '__opts__', __opts__)
#print output(json.load(sys.stdin))
print output(json.loads(subprocess.check_output(
['pepper', '--client=runner', 'jobs.lookup_jid', 'jid=%s' % sys.argv[1]])))
But for some reason, it does not work and returns:
return:
Data failed to compile:
----------
[...]
Any idea why it does not work?
from pepper.
pepper is really nice... this feature would be icing on the cake!
from pepper.
@bbinet nice one ! Thanks a bunch...
from pepper.
Note that I've submitted PR saltstack/salt#41090 to make the profiling option work (it currently raises an exception)
from pepper.
@bbinet thanks!
from pepper.
The next version of pepper will use the salt outputters if salt is installed.
from pepper.
@gtmanfred glad to hear that... great news!
from pepper.
I solved the format problem by "pip/pip3 install salt"
from pepper.
Related Issues (20)
- [BUG] Can't send pillar data in kwarg HOT 2
- using pepper with tokens does not honor profiles HOT 1
- Add changelog HOT 1
- Release 0.7.6 breaks --fail-any-none flag HOT 1
- Server error on jobs.lookup_jid with runner client HOT 3
- saving the response to file on MacOS add random characters HOT 4
- pepper.cmd wrapper not included in pip package
- No way to pass tgt_type to API HOT 1
- Should provide a logout function
- Unable to use --state-output=mixed --state-verbose=false with pepper HOT 2
- TLS issues are always ignored HOT 1
- Migrate Travis CI jobs to GitHub Actions HOT 1
- Installing salt-pepper 0.5.5-1 on ubuntu 20.04 failing: cli.py:474: SyntaxWarning: "is not" with a literal. Did you mean "!="?
- Makefile not working on ubuntu 18.04 dev machine
- ~/.pepperc not referred on latest 0.7.6 HOT 1
- Using pepper to get list of registered salt-minions ? HOT 2
- Fix failing test suite HOT 1
- Pepper no longer respecting --out flag HOT 5
- [CI] Remove Python 3.7 in favor of 3.11
- pytest.helpers.remove_stale_minion_key not registered
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pepper.