diff options
-rw-r--r-- | pillar/top.sls | 4 | ||||
-rw-r--r-- | salt/_modules/nbroles.py | 12 | ||||
-rw-r--r-- | salt/top.sls | 4 |
3 files changed, 16 insertions, 4 deletions
diff --git a/pillar/top.sls b/pillar/top.sls index 37638b7..872dc8b 100644 --- a/pillar/top.sls +++ b/pillar/top.sls @@ -1,5 +1,5 @@ -{% set roles = salt['grains.get']('roles', []) %} -{% set id = salt['grains.get']('id') %} +{%- set id = salt['grains.get']('id') -%} +{%- set roles = salt['nbroles.get'](id) -%} {{ saltenv }}: '*': diff --git a/salt/_modules/nbroles.py b/salt/_modules/nbroles.py new file mode 100644 index 0000000..54c4b79 --- /dev/null +++ b/salt/_modules/nbroles.py @@ -0,0 +1,12 @@ +#to-do: tidy this up, make host configurable + +import requests + +host = 'http://127.0.0.1:5000/roles?machine=' + +def get(name): + req = requests.get(host + name) + if req.status_code == 404: + return([]) + if req.status_code == 200: + return(req.json()['roles']) diff --git a/salt/top.sls b/salt/top.sls index d937aad..a534cc5 100644 --- a/salt/top.sls +++ b/salt/top.sls @@ -1,5 +1,5 @@ -{% set client_id = salt['grains.get']('id') %} -{% set roles = salt['grains.get']('roles', []) %} +{%- set id = salt['grains.get']('id') -%} +{%- set roles = salt['nbroles.get'](id) -%} {{ saltenv }}: '*': |