Salt (SaltStack) dynamic inventory
Salt (SaltStack Inc.) is a powerful automation tool that I’ve been using for many years. This post shows an example of agent‑less usage with salt-ssh, using a dynamic inventory via a roster and an Ansible inventory plugin.
Roster example
JSON example for dynamic inventory:
# cat /srv/dynamic_inventory/roster/do
#!/bin/bash
echo '{
"all": [
"srv1"
],
"_meta": {
"hostvars": {
"srv1": {
"ansible_ssh_user": "root",
"ansible_ssh_host": "111.111.111.111"
}
}
}
}'
Run Salt ping
# salt-ssh -i --key-deploy --roster ansible --roster-file /srv/dynamic_inventory/roster/do srv1 test.ping
srv1:
True
Run command
# salt-ssh -i --key-deploy --roster ansible --roster-file /srv/dynamic_inventory/roster/do srv1 cmd.run "id"
srv1:
uid=0(root) gid=0(root) groups=0(root) context=unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023
Run without inventory
It also works fine without a pre‑defined inventory:
# salt-ssh -i --key-deploy --user=alve --sudo --roster=scan '111.111.111.111' cmd.run "id"
111.111.111.111:
uid=0(root) gid=0(root) groups=0(root)
Minimal SaltStack infrastructure
This repository shows a minimal SaltStack infrastructure setup for a master server. It demonstrates the basic configuration and server roles so you can quickly deploy a working master (or even a “Master of Masters”). You can check out the repository here: https://github.com/alan-lt/salt-infra.
For official best practices, see the SaltStack Best Practices guide. This project follows those guidelines where applicable, but focuses on a minimal, practical setup.
Comments
Post a Comment