salt.roster.ansible

Read in an Ansible inventory file or script

Flat inventory files should be in the regular ansible inventory format.

[servers]
salt.gtmanfred.com ansible_ssh_user=gtmanfred ansible_ssh_host=127.0.0.1 ansible_ssh_port=22 ansible_ssh_pass='password'

[desktop]
home ansible_ssh_user=gtmanfred ansible_ssh_host=12.34.56.78 ansible_ssh_port=23 ansible_ssh_pass='password'

[computers:children]
desktop
servers

[names:vars]
http_port=80

then salt-ssh can be used to hit any of them

[~]# salt-ssh all test.ping
salt.gtmanfred.com:
    True
home:
    True
[~]# salt-ssh desktop test.ping
home:
    True
[~]# salt-ssh computers test.ping
salt.gtmanfred.com:
    True
home:
    True
[~]# salt-ssh salt.gtmanfred.com test.ping
salt.gtmanfred.com:
    True

There is also the option of specifying a dynamic inventory, and generating it on the fly

#!/bin/bash
echo '{
  "servers": {
    "hosts": [
      "salt.gtmanfred.com"
    ]
  },
  "desktop": {
    "hosts": [
      "home"
    ]
  },
  "computers": {
    "hosts":{},
    "children": [
      "desktop",
      "servers"
    ]
  },
  "_meta": {
    "hostvars": {
      "salt.gtmanfred.com": {
        "ansible_ssh_user": "gtmanfred",
        "ansible_ssh_host": "127.0.0.1",
        "ansible_sudo_pass": "password",
        "ansible_ssh_port": 22
      },
      "home": {
        "ansible_ssh_user": "gtmanfred",
        "ansible_ssh_host": "12.34.56.78",
        "ansible_sudo_pass": "password",
        "ansible_ssh_port": 23
      }
    }
  }
}'

This is the format that an inventory script needs to output to work with ansible, and thus here.

[~]# salt-ssh --roster-file /etc/salt/hosts salt.gtmanfred.com test.ping
salt.gtmanfred.com:
        True

Any of the [groups] or direct hostnames will return. The 'all' is special, and returns everything.

class salt.roster.ansible.Inventory(tgt, tgt_type='glob', inventory_file='/etc/salt/roster')

Matcher for static inventory files

class salt.roster.ansible.Script(tgt, tgt_type='glob', inventory_file='/etc/salt/roster')

Matcher for Inventory scripts

class salt.roster.ansible.Target
get_glob()

Return minions that match via glob

targets()

Execute the correct tgt_type routine and return

salt.roster.ansible.targets(tgt, tgt_type='glob', **kwargs)

Return the targets from the ansible inventory_file Default: /etc/salt/roster