ruby - Chef Automation: Global Counter / Variable? -


i have 2 chef cookbooks (and potentially more) needs unique id (integer) when executed, in best case sequential.

are there possibilities have central storage of variables, global variable not constant? can incremented each time default recipe of cookbook executed?

there no way purely chef. usual approaches either allocate id numbers hand front in node attributes or use hash of node name or other stable value. node.name.hash % 1000 give between 0 , 1000 roughly evenly distributed. unfortunately name hashing isn't designed collision resistance in mind on smaller ranges (like 0-256) can have unfortunate streak.

if want "properly" @ tools consul , zookeeper can issue sequential numbers safely in distributed situation.


Comments