1 – install salt-ssh*
wget -O - https://repo.saltstack.com/py3/debian/10/amd64/latest/SALTSTACK-GPG-KEY.pub | apt-key add - echo 'deb http://repo.saltstack.com/py3/debian/10/amd64/latest buster main' > /etc/apt/sources.list.d/saltstack.list apt update && apt install -y salt-ssh && mkdir -p /srv/salt
2 – append host configuration in roster config file
cat >> /etc/salt/roster <<EOF srv07: host: 192.168.0.7 user: root passwd: 123456 EOF
common roster file options**: |
port: 22 |
set_path: /bin:/sbin:/usr/bin:/usr/sbin |
user: root |
passwd: 123456 |
priv: /path/to/id_rsa |
3 – try to execute a command on remote host. -i “ignore-host-keys”
salt-ssh -i '*' test.ping
4 – install python3 on remote host if the command above fails. -r “execute raw command”
salt-ssh -i -r srv07 'yum -y install python3'
5 – try to execute other command on remote host
salt-ssh 'srv07' network.ip_addrs
*official installation list to all linux distros: https://repo.saltstack.com
**more roster file options: https://docs.saltstack.com/en/latest/topics/ssh/roster.html
to improve speed of ssh connections
keep all ssh connections active for 5 minutes
cat >> ~/.ssh/config <<EOF ControlMaster auto ControlPath ~/.ssh/control:%h:%p:%r ControlPersist 300s EOF