diff --git a/docs/man/isalt.1 b/docs/man/isalt.1 new file mode 100644 index 0000000..ee3398e --- /dev/null +++ b/docs/man/isalt.1 @@ -0,0 +1,410 @@ +.\" Man page generated from reStructuredText. +. +.TH "ISALT" "1" "Jan 04, 2020" "" "isalt" +.SH NAME +isalt \- ISalt Documentation +. +.nr rst2man-indent-level 0 +. +.de1 rstReportMargin +\\$1 \\n[an-margin] +level \\n[rst2man-indent-level] +level margin: \\n[rst2man-indent\\n[rst2man-indent-level]] +- +\\n[rst2man-indent0] +\\n[rst2man-indent1] +\\n[rst2man-indent2] +.. +.de1 INDENT +.\" .rstReportMargin pre: +. RS \\$1 +. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin] +. nr rst2man-indent-level +1 +.\" .rstReportMargin post: +.. +.de UNINDENT +. RE +.\" indent \\n[an-margin] +.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]] +.nr rst2man-indent-level -1 +.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]] +.in \\n[rst2man-indent\\n[rst2man-indent-level]]u +.. +.sp +ISalt is an IPython style console to facilitate the debugging or even +development of Salt code. +.sp +Salt code typically makes use of a number of \fIdunder\fP (i.e., _d_ouble +_under_score) variables such as \fB__salt__\fP, \fB__opts__\fP, \fB__grains__\fP, +\fB__proxy__\fP, or \fB__pillar__\fP, etc., which give you quick access to various +resources and features. They also have a different meaning depending on the +context \- for example, \fB__opts__\fP on the Minion side is a different object +than \fB__opts__\fP on the Master side; \fB__salt__\fP on the Minion side gives you +access to the list of Execution Modules, while \fB__salt__\fP on the Master side +provides the Runners, and so on. +.sp +The main difficulty when working with these variables is that they only make +sense when actually running Salt and having a Master and eventually one or more +Minions running. It often happens that you don\(aqt necessarily want to have these +services running when writing a new function (that use these dunders), or just +want to quickly debug something without pushing code to production. +.sp +With ISalt, you can easily get access to these variables, by simply executing +\fBisalt\fP, e.g., +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt +>>> __salt__[\(aqtest.ping\(aq]() +True +>>> +>>> __grains__[\(aqosfinger\(aq] +\(aqUbuntu\-18.04\(aq +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +In other words, ISalt is an enhanced IPython console which gives you access to +the Salt global variables typically used in Salt code. +.SH INSTALL +.sp +ISalt is distributed via PyPI, and you can install it by executing: +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ pip install isalt +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Dependencies: +.INDENT 0.0 +.IP \(bu 2 +\fI\%salt\fP +.IP \(bu 2 +\fI\%IPython\fP +.UNINDENT +.sp +No specific version for either of these packages, so it doesn\(aqt mess up with +your environment. It should normally work well with any version. +.SH USAGE +.sp +You can configure various bits of data or conditionals using one or more of the +following options, with precedence in this order: ISalt configuration file, +environment variables, and CLI arguments. +.sp +One of the most important details to keep in mind is the difference between +running the code on the Minion side, versus Master side (where we can further +distinguish between code to be executed as a Runner, vs. Execution Module for +an arbitrary Minion \-\- for the former you may need to provide the Minion ID +using the \fB\-\-minion\-id\fP CLI argument). +.sp +Typically, when you install ISalt where you have a Salt Minion running, it +should be sufficient to execute just \fB$ isalt\fP\&. +.sp +When you want to use ISalt on the Master side, but to test Execution Modules, +you can run \fB$ isalt \-\-on\-master\fP\&. +.sp +When you\(aqre looking into evaluating Runner code, you can only do this one the +Master side, therefore, you\(aqd need to start the console as \fB$ isalt +\-\-master\fP\&. +.sp +You can check the complete list of CLI optional arguments by +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt \-h +usage: isalt [\-h] [\-\-saltenv SALTENV] [\-\-pillarenv PILLARENV] [\-c CFG_FILE] + [\-e CFG_FILE_ENV_VAR] [\-\-minion\-cfg MINION_CFG_FILE] + [\-\-master\-cfg MASTER_CFG_FILE] [\-\-minion] [\-\-master] + [\-\-minion\-id MINION_ID] [\-\-on\-minion] [\-\-on\-master] + +ISalt console + +optional arguments: + \-h, \-\-help show this help message and exit + \-\-saltenv SALTENV Salt environment name. + \-\-pillarenv PILLARENV + The Salt environment name to compile the Pillar from. + \-c CFG_FILE, \-\-cfg\-file CFG_FILE + The absolute path to the ISalt config file. + \-e CFG_FILE_ENV_VAR, \-\-env\-var CFG_FILE_ENV_VAR + The name of the environment variable pointing to the + ISalt config file. + \-\-minion\-cfg MINION_CFG_FILE + The absolute path to the Minion config file. + \-\-proxy\-cfg PROXY_CFG_FILE + The absolute path to the Proxy Minion config file. + \-\-master\-cfg MASTER_CFG_FILE + The absolute path to the Master config file. + \-\-minion Prepare the Salt dunders for the Minion. + \-\-proxy Prepare the Salt dunders for the Proxy Minion. + \-\-master Prepare the Salt dunders for the Master. + \-\-local Override the Minion config and use the local client. + This option loads the file roots config from the + Master file. + \-\-minion\-id MINION_ID + The Minion ID to compile the Salt dunders for. This + argument is optional, however it may fail when ISalt + is not able to determine the Minion ID, or take it + from the environment variable, etc. + \-\-on\-minion Whether should compile the dunders for the Minion + side, starting the ISalt console on the Minion + machine. The main difference is that the Pillar and + Grains are compiled locally, while when using \-\-on\- + master, it\(aqs using the local cached data. + \-\-on\-master Whether should compile the dunders for the Minion + side, starting the ISalt console on the Master + machine. This option is ignored when used in + conjunction with \-\-master. +.ft P +.fi +.UNINDENT +.UNINDENT +.SS Usage Examples +.SS Using ISalt on the Master +.sp +Start with \fBisalt \-\-master\fP\&. Remember that the \fB__salt__\fP dunder currently +maps to the Runner functions, and not to the execution modules. +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt \-\-master + +In [1]: # execute the \(ga\(gatest.sleep\(ga\(ga Runner: + +In [2]: # https://docs.saltstack.com/en/latest/ref/runners/all/salt.runners.test.html#module\-salt.runners.test + +In [3]: __salt__[\(aqtest.sleep\(aq](1) +1 +Out[3]: True +.ft P +.fi +.UNINDENT +.UNINDENT +.SS Using ISalt on the Master, loading the (Proxy) Minion dunders +.sp +In this mode, you need to specify the Minion ID to use and collect and compile +data for (otherwise it\(aqll use local machine\(aqs hostname): +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt \-\-on\-master \-\-minion\-id jerry +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +\fBNOTE:\fP +.INDENT 0.0 +.INDENT 3.5 +You can equally specify the Minion ID in the proxy/minion configuration +file, from \fB\-\-minion\-cfg\fP or \fB\-\-proxy\-cfg\fP options. +.UNINDENT +.UNINDENT +.sp +For Proxy Minions, you have to pass the \fB\-\-proxy\fP CLI argument, e.g., +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt \-\-on\-master \-\-minion\-id edge\-router \-\-proxy +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +For Proxy Minions, in order to load the \fB__salt__\fP modules correctly, you may +have to provide the \fBproxytype\fP as well into the Proxy configuration file (by +default at \fB/etc/salt/proxy\fP, or a different path set using the +\fB\-\-proxy\-cfg\fP arg) \- or using the \fB\-\-proxytype\fP CLI argument, e.g., +.sp +\fB/etc/salt/proxy\fP +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +proxy: + proxytype: napalm +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +And execute as \fBisalt \-\-on\-master \-\-proxy \-\-minion\-id jerry\fP\&. +.sp +Or directly as \fBisalt \-\-on\-master \-\-proxytype napalm \-\-minion\-id jerry\fP\&. +.SS Using ISalt on the (Proxy) Minion +.sp +This is the default ISalt mode, and you no longer have to provide the Minion +ID, as it\(aqs collected from local machine, unless you want to use a specific +one. As always, you can have the Minion ID in the Proxy / Minion configuration +file, the \fBISALT_MINION_ID\fP environment variable, or the ISalt configuration +file (as the \fBminion_id\fP option). +.sp +Example: +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ echo $ISALT_MINION_ID +jerry +$ isalt + +In [1]: __opts__[\(aqid\(aq] +Out[1]: \(aqjerry\(aq +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +\fBNOTE:\fP +.INDENT 0.0 +.INDENT 3.5 +The local Proxy / Minion key must be accepted by the Master. To avoid +connecting to the Master, you can use the \fB\-\-local\fP argument to start the +Minion in \fI\%Masterless\fP +mode \- you will however need to make sure that you point to the file (and +pillar) roots you need as those won\(aqt be pulled from the Master. +.sp +One good way to deal with this is pointing the \fBfile_roots\fP option to the +cache directory of the production Minion. For example, you have a Minion +that is pulling the production files from the Master, and caching them +under \fB/var/cache/salt/minion/files/base\fP (whatever would be your +filesystem backend). Now, to use these files when starting ISalt in local +mode, you can reference that dir as: +.sp +\fB/etc/salt/minion\fP (excerpt) +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +file_roots: + base: + \- /var/cache/salt/minion/files/base +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Now, starting with \fBisalt \-\-local\fP, you still load your modules, states, +and other files without connecting to the Master. +.UNINDENT +.UNINDENT +.SS ISalt configuration file +.sp +Every of the options presented above are available through the ISalt +configuration file, by default \fB/etc/salt/isalt\fP\&. To read the file from +a specific path, use the \fB\-c\fP / \fB\-\-cfg\-file\fP args, e.g., +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ isalt \-c /path/to/isalt/config/file +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Or, alternative, using the \fBISALT_CFG_FILE\fP environment variable, e.g., +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ echo $ISALT_CFG_FILE +/path/to/isalt/config/file +$ isalt +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +Even more, if you want to read the path to the config file from a different +environment variable, use the \fB\-e\fP / \fB\-\-env\-var\fP arg: +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +$ echo $ALTERNATIVE_ISALT_CFG_FILE +/path/to/another/isalt/config/file +$ isalt \-e ALTERNATIVE_ISALT_CFG_FILE +.ft P +.fi +.UNINDENT +.UNINDENT +.SS ISalt configuration file example +.INDENT 0.0 +.INDENT 3.5 +.sp +.nf +.ft C +on_master: true +proxytype: dummy +proxy_cfg: /path/to/proxy/config +minion_cfg: /path/to/minion/config +master_cfg: /path/to/master/config +.ft P +.fi +.UNINDENT +.UNINDENT +.sp +With the configuration file above, you can simplify the CLI usage, e.g., from +\fBisalt \-\-on\-master \-\-proxy\-cfg /path/to/proxy/config \-\-proxytype dummy +\-\-minion\-id jerry\fP to just \fBisalt \-\-minion\-id jerry\fP, etc. +.SS Environment Variables +.INDENT 0.0 +.TP +.B \fBISALT_CFG_FILE\fP +Absolute path to the ISalt configuration file. +.TP +.B \fBISALT_ROLE\fP +The Salt system role. Choose between: \fBmaster\fP, \fBminion\fP, or \fBproxy\fP\&. +.TP +.B \fBISALT_ON_MASTER\fP +If you\(aqre running ISalt on the Master. +.TP +.B \fBISALT_MINION_ID\fP +The Minion ID to use. +.TP +.B \fBISALT_PROXYTYPE\fP +The Proxy Minion module name to use. +.TP +.B \fBISALT_MASTER_CONFIG\fP +Absolute path to the Master configuration file. +.TP +.B \fBISALT_MINION_CONFIG\fP +Absolute path to the Minion configuration file. +.TP +.B \fBISALT_PROXY_MINION_CONFIG\fP +Absolute path to the Proxy Minion configuration file. +.TP +.B \fBISALT_USE_CACHED_PILLAR\fP +When starting in Proxy / Minion mode, on the Master: whether to use the +cached Pillars that may be already available for the specified Minion, +or compile fresh data. +.UNINDENT +.SH AUTHOR +Mircea Ulinic +.SH COPYRIGHT +2019-2020, Mircea Ulinic +.\" Generated by docutils manpage writer. +. diff --git a/setup.py b/setup.py index 12faa64..c6e5a1d 100644 --- a/setup.py +++ b/setup.py @@ -49,5 +49,5 @@ include_package_data=True, install_requires=reqs, entry_points={'console_scripts': ['isalt=isalt.scripts:main']}, -# data_files=[('man/man1', ['docs/man/isalt.1'])], + data_files=[('man/man1', ['docs/man/isalt.1'])], )