Accessing custom grain from orchestrate runner

464 views
Skip to first unread message

Pier B.

unread,
Apr 4, 2017, 4:04:16 PM4/4/17
to Salt-users
Hi,

I planned to use a custom grains defined on minion trhough the orch runner, but :

https://github.com/saltstack/salt/issues/21404

I define a custom grain equal to a substring of hostname (on minion) and then use this as a client name :

# Set client grain
{% set client_name = salt.grains.get('host').split('-')[1] %}
grain client_NAME
:
  grains
.present:
   
- name: client_NAME
   
- value:  {{ client_name }}

But when using orch runner I cannot access this grain, anyone knows about a way to replicate this behaviour without using the custom grain (which is actually set in grain file on minion) ?

Something like recreating the
{% set client_name = salt.grains.get('host').split('-')[1] %}

But on orchestrate runner....


Thanks a lot  !

Pier B.

unread,
Apr 4, 2017, 5:07:13 PM4/4/17
to Salt-users
Hum I just thought I might be using salt mine for this, would it work in may case ? I mean would the grain / data be available in the middle of an orch state run ?

Seth House

unread,
Apr 4, 2017, 5:16:51 PM4/4/17
to salt users list
That issue is referencing custom grain modules, not grain values.

Calling `salt.grains.get()` references the grains on the machine that
is executing that SLS file. Orchestrate files are run on the Master,
they're essentially a Master-side state run.

Now it's very common to use Orchestrate to start state run on one or
more Minions, but that would be running a separate SLS file on those
minions. The syntax you have above should work in that file.

# /srv/salt/the_orchestrate.sls
start_state_run:
salt.state:
- tgt: <the minion>
- sls:
- the_state_run

# /srv/salt/the_state_run.sls
...stuff with grains.present here...
> --
> You received this message because you are subscribed to the Google Groups
> "Salt-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to salt-users+...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/salt-users/cf768ac0-bca1-4cb6-b89b-099fee7a9b8b%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Pier B.

unread,
Apr 4, 2017, 7:21:37 PM4/4/17
to Salt-users, se...@eseth.com
Thanks Seth for the details about the issue I was referencing, I missed a point back there you're so right !
I couldn't accept my case was not a standard one, so thanks a lot for pointing me straight to the solution (haven't tried yet it's 2 in the morning here, going to sleep now !).


Thanks Seth
Reply all
Reply to author
Forward
0 new messages