Documentation | |
---|---|
Name: | Useful SALT commands (cheatsheet) and recipes |
Description: | Cheatsheet of SALT commands and quick recipes |
Modification date : | 15/10/2018 |
Owner: | warlock86@gmail.com |
Notify changes to: | backops |
Tags: |
salt-run manage.up
salt '<HOSTNAME>' grains.ls
salt '<HOSTNAME>' test.ping
salt '*' cmd.run "<COMMAND>"
Double quotes must be used to run “complex” commands:
salt '*' cmd.run "ip ad"
Like running remote commands with ssh
No wildcard/regexp available, sorry:
salt '*' pkg.list_pkgs
salt '*' pkg.install 'PKGNAME'
No functcion available, use cmd.run
instead:
salt '*' cmd.run 'yum search PKGNAME'
salt '*' pkg.remove 'PKGNAME'
salt '*' file.copy /path/to/origin.file /path/to/destination.file
https://docs.saltstack.com/en/latest/ref/modules/all/salt.modules.systemd.html
Systemd is managed through the META-MODULE service
.
if you want that salt restart the service (dont' make me talk about systemd ), use force_reload
salt '*' service.force_reload SERVICENAME
More info in its own page.
/srv/salt/base
salt '<HOSTNAME>' state.apply
salt '<HOSTNAME>' state.apply <STATE_NAME>
salt-key -A
salt-key
salt-key -d testmongui.ciberterminal.net
Example for installing CylancePROTECT in all Crypta-INTG servers.
Please, take note that the targeting is only based on the hostname.
If you need to do a more accurate targeting take a look at this.
From SALT Master run:
CENTOS:
sudo salt -E '(?i)accli*' file.makedirs /opt/cylance/ sudo salt -E '(?i)accli*' cp.get_file salt://cylance/config_defaults.txt /opt/cylance/config_defaults.txt sudo salt -E '(?i)accli*' cp.get_file salt://cylance/CylancePROTECT.el{{grains.osmajorrelease}}.rpm /opt/cylance/CylancePROTECT.el{{grains.osmajorrelease}}.rpm template=jinja sudo salt -E '(?i)accli*' cmd.run "yum -y install /opt/cylance/CylancePROTECT.el{{grains.osmajorrelease}}.rpm" template=jinja
UBUNTU:
sudo salt -E '(?i)avclp-gray*' file.makedirs /opt/cylance/ sudo salt -E '(?i)avclp-gray*' cp.get_file salt://cylance/config_defaults.txt /opt/cylance/config_defaults.txt sudo salt -E '(?i)avclp*' cp.get_file "salt://cylance/cylance-protect.{{grains.osrelease | regex_replace('\.','') }}.x86_64.deb" "/opt/cylance/cylance-protect.{{grains.osrelease | regex_replace('\.','') }}.x86_64.deb" template=jinja #The followinf line is optional, only if Cylance instalation fails at module insert sudo salt -E '(?i)avclp*' cmd.run "sudo apt-get update -y && sudo apt-get -y install libxml2-utils make gcc linux-headers-generic" sudo salt -E '(?i)avclp*' cmd.run "dpkg -i /opt/cylance/cylance-protect.{{grains.osrelease | regex_replace('\.','') }}.x86_64.deb" template=jinja