Skip to main content

Salt -- cheat sheet

     The Salt system is a Python-based open-source remote execution framework for
configuration management, automation, provisioning and orchestration. A basic Salt
implementation consists of a Salt master managing one or more Salt minions.
Salt master:
A server running the salt-master service is a Salt master. The master provides a cohesive
platform for orchestration and automation between managed systems.
Salt minion:
A Salt minion is any system or device managed by Salt. A minion can either run the
salt-minion service or be agent less using salt-ssh or salt-proxy. A minion running the
service may execute commands without a master in stand-alone mode.
Salt proxy:
A Salt Proxy is used to execute commands on devices that are unable to run the minion
service. The proxy minion receives commands from a master, translates and transmits the
commands appropriate to the method of connection to the underlying device
(SSH, REST, etc.), and relays the results back to the master.
Salt SSH:
The Salt SSH system was added as an alternative means to communicate with minions.
It does not require that a minion be present on the target system, only that the
SSH service is running and port 22 is open.

sudo salt-run jobs.lookup_jid $job_id
sudo salt-run jobs.list_jobs search_target='MINION_ID' search_function='state.highstate'
sudo salt-run jobs.exit_success
sudo salt --async *com state.highstate queue=True
sudo salt *com saltutil.refresh_pillar
sudo salt '*'
sudo salt '*' grains.items
sudo salt --async '*' saltutil.sync_all
sudo salt --async '*' state.highstate queue=True
sudo salt '*'
sudo ls -l /opt/saltroots

sudo salt '*' saltutil.refresh_pillar
sudo salt '*' --async state.apply base.base_users_groups

sudo salt '*' state.show_sls

reports minions' running versions and compares them to the master's:
salt-run manage.up
salt-run manage.status
salt-run manage.down

list keys:
salt-key -L

list all running jobs:

| Kill the job:
| kill all jobs:
| salt '*' saltutil.kill_all_jobs
| kill the job with id:
| salt '*' saltutil.kill_job <job id>

test version:
salt '*' test.version

sudo salt minionID 'ls -l /etc' -- remotely run command on MINION
sudo salt minionID 'tail -n100 /var/log/salt/minion'

salt minionID pillar.items

salt-call -l debug state.apply

sudo salt 'host1*' state.apply common.files.files test=True --- OCI
sudo salt 'host1*' state.apply common.files.templates test=True
sudo salt 'host1*' --async state.apply base.base_users_groups.updated_users --- classic
sudo salt --async 'host1*' state.highstate test=True --state-output=changes
sudo salt-call --local --- run local salt command

salt -L `awk -vORS=, '{ print $1 }' min2 | sed 's/,$/\n/'` 'grep "^User" /etc/sudoers'
for i in $(cat min);do sudo salt-key -L|grep ^$i>>min2;done


Popular posts from this blog

Reset root pass in ESXi 5.5

    In this post i will show how to reset root password in ESXi 5.5. For this first we need any bootable linux distributor. In my example i used Ubuntu 16.04.     Boot from Ubuntu disk. Select try Ubuntu, wait for loading. After full loading open Terminal. Type fdisk -l for list all partitions hypervisor/system image is located on the first 250 MB partition (/dev/sda5) which contains the state.tgz file. Mount /dev/sda5 to /mnt sudo -s mount /dev/sda5 /mnt. Go to the /mnt cd /mnt . Copy state.tgz to /tmp folder cp state.tgz /tmp , cd /tmp. Unarchive state.tgz tar xzf state.tgz then   tar xzf local.tgz Go to the /etc directory in /tmp folder  cd etc/ . For deleting resetting password open shadow file with nano shadow  delete the password hash of ESXi root account. Close nano editor. Re add etc/ folder to local.tgz : tar czf local.tgz etc after it readd local.tgz to state.tgz: tar czf state.tgz local.tgz . Copy state.tgz mnt/ folder: cp state.tgz /mnt/ . umount /mnt 

Cheat Sheet

Bash: echo $? - exit status of last command (0 no error) ' - Single quote removes meaning special meaning of special character. find /qwe -type f -iname *.js -exec cp --parents -t /tmp/ {} + -- find all js files and copy with parent directory ystemctl set-default (ls -l /lib/systemd/system/runlevel*) -- set runlevel echo <password> | sudo -S for i in t@01 st@02 ba@sta03;do ssh -o RequestTTY=true $i "sudo -l";done -- allow tty present VIM: :r! sed -n '16,812 p' < input_file.txt -- copy line range from input_file :1,10d -- delete line from 1 to 10 :se nu -- show line numbers Apache: Redirection in Apache (By default, the Redirect directive establishes a 302, or temporary, redirect.): URL: <VirtualHost *:80> ServerName Redirect 301 /oldlocation </VirtualHo