Chef, related path from cookbook to file storage - ruby

Is it possibile to get absolute path to cookbook directory(I don't need path to cache).
What I want to do?
My structure:
Chef
-Cookbooks(tomcat, java, etc.)
-Profiles(json files with configs)
-Resources(zip files with programs)
runScript0.bat
runScript1.bat
....
How can I get path to Resources folder from recipes, I need to get files from this folder w/o hardcodded path. Of course I can download programs from svn/git, but I need this option too.

The structure you describe is not inside a cookbook so those files do not exist as far as Chef is concerned. Even inside a cookbook, you need to use a cookbook_file or remote_directory resource to write to a known place first.

Related

What is the standard way to describe the paths to config files of my ruby application (linux)?

What is the standard way to describe the paths to config files of my ruby application (linux)? (not rails, but I think it doesn't matter right now)
How does this "fit" into standard paths like /etc/ and /usr/local/etc/?
Let's say I want to put config in /usr/local/etc/myapp/config.json during global installation,
but in $HOME/.config/myapp/config.json during local installation.
I want to provide the default configuration file with my application, not pass it from somewhere else (although this is also possible, but only as an option).
Can gemspec do this? I found in the description of Gem::Specification only paths to bin and exe files, but not to configuration files.

What is a usual workflow for dealing with shared files with capistrano?

My .csv recreates on every release, and, as I understand, to keep its data unchanged between deploys I need to put it in /shared directory and simlink to it from my deploy.rb.
Is this the right route? (I have this question because I don't seem to find much info on how to do this with respect to, eg, databases, for some reason. /shared directory is mostly used for .conf files and paperclip-like directories).
When using capistrano, your application code will be "uploaded" to some directory on the server. Capistrano uses this structure:
/path_to_folder:
current - symlink to the directory with the current release
releases - contains all kept releases
shared - files that should persist between releases
So to your question - copy the .csv file somewhere into "shared" directory and then in the config/deploy.rb add this:
namespace :deploy do
task :create_symlinks do
run "ln -s #{shared_path}/something.csv #{latest_release}/db/something.csv"
end
end
after 'deploy:update_code', 'deploy:create_symlinks'
Replace "something" with the file name that you copied. You can also put the csv file into some directory under "shared" if you want to, I'd use "db" in this case. If you do so, don't forget to update path in the symlink.

How to add cookbooks from chef documentation

I am a new to chef cookbooks and currently working on a task. I have already completed the tutorial on chef.io but i am struggling to understand how can i install a cookbook provided at chef-io.
So as of now, I have downloaded the cookbook. Its .tar file and i extracted it. I can see respective default.rb and other files but i am unable to get that how can i add this cookbook to my existing cookbooks which are creating a vm image.
Is there any guide or tutorial that i can follow ?
In addition to Josh's answer it sounds to me like want to add it to your chef-repo after downloading it and extracting the gzip file?
Just add the maven directory to your cookbooks directory. Or you could just do knife cookbook site install maven from within your chef-repo directory.
Or maybe you want to upload it to your Chef Server?
knife cookbook upload maven See: https://docs.chef.io/knife_cookbook.html#upload
If I'm understanding your question correctly, then what you need to do is create a Chef role, and then list all of the recipes that you want to execute in your role's run_list. As for documentation, check out Chef's documentation on roles: Chef Roles
Firstly if i get your question right, you are trying to download an already existing cookbook from the community. If so, you can follow these steps :
1) Download the cookbook which is in the .tar format as you specified, extract it and place that particular cookbook within your chef-repo path from where you want to upload it.
2) Once done, do a "knife cookbook upload cookbook-name"
Now the main part is, if you are trying to upload this cookbook and make it part of your already existing run-list. You need to add this within the run-list.
Else if you are doing it via role, you will need to add this cookbook recipe within your role's run-list.
But keep in mind, whatever cookbook's you download from the community might have dependencies on other cookbook's so choose wisely. The lesser cookbook's the better as this makes your run-list converge faster for a faster chef-client run.
Hope this helps.
Regards,
Akshay

How to select thousands of file in chef recipe

I have a lot of csv files that should be placed in a server.
So I put it in a directory my-cookbook/files/default/ and I want to load all csv files by using Dir.glob method, but I don't know how to set proper relative path for it.
Dir.glob("#{relative_path}/*.csv").each do |file|
cookbook_file "/var/foo/#{File.basename(file)}" do
source File.basename(file)
end
end
I tried with Dir.glob("*.csv"), but it didn't work.
How can I load all files in files/default directory?
This isn't really how Chef is designed to be used. You would be better off putting all your files in something like a git repo or remote tarball and using things like the git or remote_file resources to download them. cookbook_file is really only a hack for small, one-off things. Honestly I don't really use it much, I would recommend you do the same.

How to change Controllers/Models source directory in CodeIgniter

I need to load controllers and models from a different folder than the default one. I am using a Linux system.
I am building a simple CI application for some people, for use on a shared hosting I own. But I want to give them access only to /views folder and some /config files. And this is why I need to store the controllers and models in a different folder on the same level as /public_html folder or maybe somewhere in the linux system.
I consider this would be a better solution than encoding files
CodeIgniter permits you to organize your controllers,views and config files into sub-folders. As far as I know it doesn't permit it for models (at least documentation doesn't mention it, I've not tried myself).
As your are in a Linux system, you can create a symbolic link to reference to another directory in the filesystem.
So you can create the directories:
application/config/public
application/controllers/public
application/views/public
And then create in your /public_html symbolic links ponting to these directories:
/public_html/config -> application/config/public
/public_html/controllers -> application/controllers/public
/public_html/views ->application/views/public
When your customers upload files to /public_html/config, they will be also available in application/config/public. The same applies for /public_html/controllers and /public_html/views.
The command syntaxis to creates symlinks is
# ln -s target name
i.e:
# ln -s application/config/public /public_html/config
If you don't have console access to your hosting you can create the links using the PHP function symlink() .
To load a view/config/controller from a subfolder you only have tu prepend the directory name in the $this->load->...() function call. i.e:
$this->load->view('public/my_view);
Check CI documentation for more info about organizing your files into sub-folders.

Resources