How to assign Grains data into reactor.sls file

68 views
Skip to first unread message

Ranjithkumar T

unread,
Nov 30, 2016, 1:27:40 AM11/30/16
to Salt-users
Hi,

I have 3 minions(minion1, minion2, minion3) for testing the event reactor system and its worked as expected until when i give the specific target minion id manually on my reactor.sls(here it is: /srv/salt/reactor/onemorchck.sls), But i would like to assign the minion id through grains data based on the event,

that is, if i fire the event "onemore/check" from minion2 then the reactor config should be react / touch the file only on minion2(the minion id value should assign by the grain data and not manually) and as same for other two minions

kindly check the error when i add - tgt: {{ data['id'] }} alone in the reactor file:

2016-11-29 15:55:24,480 [salt.utils.templates][ERROR   ][13684] Rendering exception occurred: Jinja variable 'dict object' has no attribute 'act'
2016-11-29 15:55:24,481 [salt.utils.reactor][ERROR   ][13684] Failed to render "/srv/salt/reactor/onemorchck.sls":
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/salt/utils/reactor.py", line 68, in render_reaction
    data=data)
  File "/usr/lib/python2.7/dist-packages/salt/state.py", line 304, in render_template
    template, self.rend, self.opts['renderer'], **kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/template.py", line 95, in compile_template
    ret = render(input_data, saltenv, sls, **render_kwargs)
  File "/usr/lib/python2.7/dist-packages/salt/renderers/jinja.py", line 69, in render
    **kws)
  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 178, in render_tmpl
    output = render_str(tmplstr, context, tmplpath)
  File "/usr/lib/python2.7/dist-packages/salt/utils/templates.py", line 386, in render_jinja_tmpl
    buf=tmplstr)
SaltRenderError: Jinja variable 'dict object' has no attribute 'act'

On the salt-master my reactor config files are,

root@ranjith1:~# cat /etc/salt/master.d/reactor.conf
reactor:
 - 'onemore/check':
   - /srv/salt/reactor/onemorchck.sls

root@ranjith1:~# cat /srv/salt/reactor/onemorchck.sls
{% if data['retcode'] == 0 and data['success'] == True and data['fun'] == 'saltutil.sync_grains' %}
onemore_check:
 local.file.touch:
  - tgt: {{ data['id'] }}
  - kwargs:
     queue: True
#  - tgt: 'id:minion2'
#  - expr_form: grain
  - arg:
    - /working_fine
{% endif %}

Kindly suggest me what am doing wrong in the reactor.sls(/srv/salt/reactor/onemorchck.sls) and how to assign the random / grains value on this file to target the particular minion which fires the event.

Regards,
Ranjithkumar.T
Reply all
Reply to author
Forward
0 new messages