Reputation: 105
I want to have
salt 'target' grains.items
return a result with a grain, that is an empty list:
target:
...other grains...
grain_name:
None
...other grains...
So, later, I can run this custom salt state and use salt.states.grains.append. My custom salt state (via a sls file, named grains_name_state.sls, in /srv/salt/_files) is as follows:
grain_name:
grains.append:
- value: whatever_value
My custom grains module (via a python file, named custom_grain.py, in /srv/salt/_grains on the master) is as follows:
#!/usr/bin/env python
def my_custom_grain():
#initialize an empty grains list for the grain 'grain_name'
grains = {}
grains['grain_name'] = []
return grains
So, calling
salt 'target' saltutil.sync_grains
should load the custom grain into the target minion. And then, salt 'target' grains.items
should contain the results for the target and show the 'grains_name' value as None. But instead it contains this:
target:
...other grains...
grain_name:
...other grains...
Then, when I try, salt 'target' state.apply grains_name_state
, it yields a failure saying 'Comment: Grain grain_name does not exist'
Upvotes: 1
Views: 1007
Reputation: 105
Figured it out; though, I am not sure why salt.states.list_append works when the grain should be a list-type and be append-able. Working with Saltstack 2016.3.3+, my custom salt state (via a sls file, named grains_name_state.sls, in /srv/salt/_files) is as follows:
grain_name:
grains.list_present:
- value: whatever_value
Then, after the first highstate/state.apply, the grain_name grain is available to use list_present (a duplicate append command) on.
Upvotes: 0