Thursday, December 31, 2015

Salt common modules

sys.docReturn the docstrings for all execution modules and functions
  • salt * sys.doc test.ping
  • salt-call sys.doc test
  • salt-call sys.doc  # To see documentation for all modules
sys.state_doc: Get help for state modules and functions. Return the docstrings for all states.
  • salt-call sys.state_doc user.present
sys.list_modules: List the execution modules loaded on the minion
  • salt-call sys.list_modules
sys.list_functionsList the execution functions for all modules. 
  • salt-call sys.list_functions sys 


sys.list_state_modules: List the state modules loaded on the minion
  • salt-call sys.list_state_modules
sys.list_state_functions: List the functions for all state modules.
  • salt-call sys.list_state_functions user
cmd.run: Execute the passed command and return the output as a string
  • salt * cmd.run 'uptime'
  • salt * cmd.run 'date'
  • salt * cmd.run 'grep root /etc/passwd'
  • salt-call cmd.run cwd=/usr 'pwd'
  • salt * cmd.run whoami runas=vagrant #by default commands are run with root.
  • salt-call cmd.run env='{foo: bar}' 'echo $foo' #set environment variable
pkg.list_pkgsList the packages currently installed
  • salt * pkg.list_pkgs
pkg.available_version: See What Version Will Be Installed
  • salt * pkg.available_version nginx
pkg.installInstall the passed package(s)
  • salt centos65-minion pkg.install nginx
pkg.versionReturns a string representing the package version or an empty string if not installed. 
  • salt centos65-minion pkg.version nginx
user.addAdd a user to the minion
  • salt centos65-minion user.add wilma
  • salt centos65-minion cmd.run 'grep wilma /etc/passwd'     #verify
user.list_usersReturn a list of all users
  • salt centos65-minion user.list_users
user.infoReturn user information
  • salt centos65-minion user.info wilma
saltutilThe Saltutil module is used to manage the state of the salt minion itself. It is used to manage minion modules as well as automate updates to the salt minion.

saltutil.sync_modulesSync the modules from the _modules directory on the salt master file server.
  • salt vagrant-centos65.vagrantup.com saltutil.sync_modules
saltutil.sync_allSync down all of the dynamic modules from the file server for a specific environment. This function synchronizes custom modules, states, beacons, grains, returners, output modules, renderers, and utils.
  • salt vagrant-centos65.vagrantup.com saltutil.sync_all
saltutil.runningReturn the data on all running salt processes on the minion
  • salt vagrant-centos65.vagrantup.com cmd.run 'sleep 100'
  • salt vagrant-centos65.vagrantup.com saltutil.running
saltutil.kill_jobSends a kill signal (SIGKILL 9) to the named salt job's process
  • salt vagrant-centos65.vagrantup.com saltutil.kill_job 20151231192241285570
 cp.list_states: List all of the available state modules in an environment
  • salt vagrant-centos65.vagrantup.com cp.list_states
state.show_highstate: Retrieve the highstate data from the salt master and display it
  • salt ubuntu-14.04-amd64-vbox state.show_highstate

No comments: