Salt (SaltStack) dynamic inventory

Salt (SaltStack inc.) pretty cool tools for automation with I use many years. Here example of agent-less (salt-ssh) usage with dynamic inventory (roster and Ansible inventory plugin).

Json example
# 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 function
# salt-ssh -i --key-deploy --roster ansible --roster-file /srv/dynamic_inventory/roster/do srv1 test.ping
srv1:
    True

Run cmd
# 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

BTW, work fine without inventory at all
# 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)

Comments

Popular posts from this blog

FreeRadius and Google Workspace LDAP

pssh (parallel-ssh) problems on Debian 10 with Python 3.7