Open jayhendren opened 5 years ago
I suspect this is to do with the accumulator pattern.it sounds like something earlier on in the run is altering the share resource. Then the last share isn't getting a chance to be added to the collection. This is strictly the correct behaviour. Though that doesn't mean desired!
I would suggest putting the samba server and the share resource together so they fail together, and don't alter the file.
If that doesn't work, or I'm completely off the mark here. Let me know and we cna further dig into this problem.
Yes, this seems to be a common problem in community cookbooks that use the accumulator pattern.
I believe your suggestion...
...putting the samba server and the share resource together so they fail together, and don't alter the file.
... will work in my particular case. At least, it fixed the issue in the quick-and-dirty testing that I've been doing. However, it doesn't work in all cases. When the accumulated resources are spread out across multiple cookbooks, it becomes impossible to group them together - I ran into this issue with the firewall cookbook, for instance.
Yeah we really don't like using the accumulator pattern, but are usually forced into it when there is no conf.d directory for the software.
Technically, I'm not sure there's a lot we can do apart from the above suggestion of keeping together resources. Especially if in between those resources you have things that are likely to fail.
smb.conf supports an include
directive, so maybe creating a samba.conf.d directory would work even if it's not the default or typical configuration file layout for samba? Just kind of spitballing here - switching to that pattern would obviously be an enormous design change from the current cookbook.
If we think we can get that working, and you and point me at that documentation! That'd be awesome.
Well it may be a moot point. Turns out smb.conf does not support wildcard includes, only a single file at a time. So even with includes, it would probably be necessary to use an accumulator to build the list of files to include.
References:
Do we think this is possible to do, or it should be documented it isn't recommended to structure the resources in the way you're doing?
Cookbook version
1.2.0
Chef-client version
14.2.0
Platform Details
RHEL 7.6
Scenario:
Steps to Reproduce:
Run the following recipe:
Half the time this recipe will execute successfully, causing the correct config file to get written out:
Half the time this recipe will fail. This causes an incorrect configuration file, missing the shares, to get written out:
This recently caused a service interruption on one of our customer's systems. A yum repository resource, unrelated to samba, failed. This caused samba to write out the config without any shares. As a result, all of the customer's shares went away.
Expected Result:
When the recipe fails, existing shares should be remain intact in order to avoid service interruptions.
Actual Result:
When the recipe fails, existing shares are removed from the configuration file, causing service interruptions.