You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've built out a custom resource which calls the Chef directory and cookbook_file native resources. It correctly lays the cookbook_file in the directory which was created beforehand. In the recipe I then call managed_directory with the recursive set to true. It seems as though the managed_directory resource doesn't take into account any file or directory resources created inside custom resources
Expected Result
The file and directory shouldn't get deleted as they were created by Chef in the custom resource
Actual Result
The file and directory get deleted when the managed_directory resource is called.
action:createdodirectory_path= :: File.join('/test/blargh',new_resource.folder_prefix.to_s)# Basically it's now equal to '/test/blargh/0'directorydirectory_pathdorecursivelytrueend# Lay down the cookbook file to '/test/blargh/0/test_file.sh'cookbook_file ::File.join(directory_path,new_resource.name)dosourcenew_resource.sourceowner'root'group'root'mode'0755'action:createendend
Kitchen Logs
* custom_resource [test.sh] action create
* directory[/test/blargh/0] action create
- create new directory /test/blargh/0
* cookbook_file[/test/blargh/0/test_file.sh] action create
- create new file /test/blargh/0/test_file.sh
- update content in file/test/blargh/0/test_file.sh from none to 51ed9e
--- /test/blargh/0/test_file.sh 2018-10-24 14:12:31.651284200 +0000
+++ /test/blargh/0/test_file.sh20181024-281-ck0gx4 2018-10-24 14:12:31.651284200 +0000
@@ -1 +1,11 @@
+#!/bin/bash
+
+echo "Test"
- change mode from '' to '0755'
- change owner from '' to 'root'
- change group from '' to 'root'
* managed_directory[/test/blargh] action clean
* directory[/test/blargh/0] action delete
- delete existing directory /test/blargh/0
Platform: CentOS 7.4 Chef Client Version: 14.3.37 Workaround: So it does seem like there's a workaround, but it seems rather inconvenient to do. In the custom resource, change the directory and the cookbook file to this:
This will add the resources to the RunContext, but there must be a way to not only scan the main RunContext but also scan any custom resources which also use recipe DSL?
The text was updated successfully, but these errors were encountered:
Same problem here! With latest chef-client and motd cookbook. manage_directory is now useless in our environment. Hopefully somebody is able to fix this bug, soon.
Apologies to @rhughes1 for never replying to the very well reported issue, and sorry that @lehn-etracker also has this problem.
I've attempted to write tests reproducing the issue, but I have not been successful. My work is in branch https://github.com/zts/chef-cookbook-managed_directory/tree/update_tests , which introduce a simple custom resource which uses the file and directory resources. Surprisingly, manage_directory appears to work.
I'm not sure what I'm doing wrong with the tests, as I'm 100% certain that the problem exists. I figured it would be possible to solve this using the event system, and the change in this PR also looks promising.
I don't currently use this cookbook, but if you can give me a failing test then I'll see if I can figure it out.
Description:
I've built out a custom resource which calls the Chef directory and cookbook_file native resources. It correctly lays the cookbook_file in the directory which was created beforehand. In the recipe I then call
managed_directory
with the recursive set to true. It seems as though the managed_directory resource doesn't take into account any file or directory resources created inside custom resourcesExpected Result
The file and directory shouldn't get deleted as they were created by Chef in the custom resource
Actual Result
The file and directory get deleted when the
managed_directory
resource is called.Steps to Reproduce
Create the following
Recipe:
Custom Resource
Kitchen Logs
Platform: CentOS 7.4
Chef Client Version: 14.3.37
Workaround: So it does seem like there's a workaround, but it seems rather inconvenient to do. In the custom resource, change the directory and the cookbook file to this:
This will add the resources to the RunContext, but there must be a way to not only scan the main RunContext but also scan any custom resources which also use recipe DSL?
The text was updated successfully, but these errors were encountered: