@@ -0,0 +1,1186 @@
+'''%0AManage grains on the minion. This state allows for grains to be set and unset%0A'''%0A%0Adef present(name, value):%0A    '''%0A    Ensure that a grain is set%0A%0A    name%0A        The grain name%0A%0A    value%0A        The value to set on the grain%0A    '''%0A    ret = %7B'name': name,%0A           'changes': %7B%7D,%0A           'result': True,%0A           'comment': ''%7D%0A    if isinstance(value, dict):%0A        ret%5B'result'%5D = False%0A        ret%5B'comment'%5D = 'Grain value cannot be dict'%0A        return ret%0A    if __grains__.get(name) == value:%0A        ret%5B'comment'%5D = 'Grain is already set'%0A        return ret%0A    if __opts__%5B'test'%5D:%0A        ret%5B'result'%5D = None%0A        if not name in __grains__:%0A            ret%5B'comment'%5D = 'Grain %7B0%7D is set to be added'.format(name)%0A        else:%0A            ret%5B'comment'%5D = 'Grain %7B0%7D is set to be changed'.format(name)%0A        return ret%0A    grain = __salt__%5B'grains.setval'%5D(name, value)%0A    if not grain == %7Bname: value%7D:%0A        ret%5B'result'%5D = False%0A        ret%5B'comment'%5D = 'Failed to set grain %7B0%7D'.format(name)%0A        return ret%0A    ret%5B'result'%5D = True%0A    ret%5B'changes'%5D = grain%0A    ret%5B'comment'%5D = 'Set grain %7B0%7D to %7B1%7D'.format(name, value)%0A    return ret%0A

Add grains state