I want to delete the line configuration (This word "configuration" is inside the angular brackets in the file "hdfs-site.xml"). I tried using this code but no luck.
ruby_block "delete_lines_in_hdfs_site" do
block do
file = Chef::Util::FileEdit.new("/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml")
file.search_file_delete_line(/<configuration>/)
end
end
You need to end the ruby block with
file.write_file
Otherwise the changes are not written out.
While I agree that using a template is preferred and considered best practices, there are times you need to edit an existing file which may have variations and not fit the template model.
You do not add to or remove lines from files with chef. Instead you replace the configuration file with yours, which you put into your cookbook under files/ or templates/ forlder.
template "/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml"
or
cookbook_file "/opt/hadoop-2.4.1/etc/hadoop/hdfs-site.xml"
When you just add/replace lines in config files, you cannot be sure, that after upgrade of installed software your config files are right.
Related
I'm using Cucumber and Aruba to test a Ruby command line app written on top of GLI. To prevent tests from affecting production data, I update ENV['HOME'] to point to a testing directory. I'd like to check for the existence of a file in the testing ENV['HOME'] directory. I'd like to use Aruba for this, but I have been unable to get ENV['HOME'] to expand properly.
For example:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "set_a" of test_arena
Then a file named "#{ENV['HOME']}/config.xml" should exist
Is it possible to pass ENV['HOME'] to Aruba's Then a file named "" should exist step_definition and have it expand to the full path?
I'm still interested in seeing if it's possible to do this natively with Cucumber/Aruba. In the mean time, here's a cut down example of what I'm doing:
In features/app_name.feature file, define the following Scenario:
Scenario: Testing config files are found
Given I switch ENV['HOME'] to be "test_arenas/set_a"
Then a test_arena file named "config.xml" should exist
Then, in the features/step_definitions/app_name.rb file define the steps:
Given(/^I switch ENV\['HOME'\] to be "(.*?)"$/) do |testing_dir|
ENV['HOME'] = File.join(File.expand_path(File.dirname(__FILE__)),
'..','..', testing_dir)
end
Then(/^a test_arena file named "(.*?)" should exist$/) do |file_name|
file_path = "#{ENV['HOME']}/#{file_name}"
expect(File.exists?(file_path)).to be_truthy
end
This isn't as robust at Aruba's check_file_presence but it gets the basic job done.
For a little more background, the idea behind this approach is to have a test_arenas directory sitting at the root of the app's directory structure. For each test, an individual test_arenas/set_X directory is created that contains the necessary files. Prior to each test, ENV['HOME'] is pointed to the respective test_arenas/set_X directory.
I have a gem that I have written that has a number of handlers, each of which has their own ruby file in the gem. I need to add the ability to specify a file on the command line that will be loaded in the same manner as these other handlers. The file will typically not be in the default load path of the gem.
I'm not sure the best way to do this. I could take the filename, and then add the containing directory to the load path and then load the file. I could have the user specify a directory containing handlers to be read instead of specifying the file, or I'm sure there are a better way to do it that I haven't yet thought of.
This was fixed using require_relative and expanding the file path using Dir.pwd:
req_path = File.expand_path(arg, Dir.pwd)
require_relative req_path
I written a Ruby tool, named foobar, having a default configuration into a
file (called .foobar).
When the tool is executed without any params, the configuration file's params
can be used: ~/.foobar.
But, if the current tool's path is ~/projects/foobar and if
~/projects/foobar/.foobar exists, then this file should be used instead of
~/.foobar.
That's why the way to look for this configuration file should start from the
current folder until the current user folder.
Is there a simple way to look for this file?
cfg_file = File.open(".foobar", "r") rescue File.open("~/.foobar", "r")
Although to be honest, I almost always do two things: provide an option for a config file path, and allow overriding of default config values. The problem with the latter is that unless you know config files are ordered/have precedence, it can be confusing.
I would do this:
if File.exists(".foobar")
# open .foobar
else
# open ~/..
end
I have a conf file that is of the format:
name=value
What I want to do is using a template, generate a result based on some values in another file.
So for example, say I have a file called PATHS that contains
CONF_DIR=/etc
BIN_DIR=/usr/sbin
LOG_DIR=/var/log
CACHE_DIR=/home/cache
This PATHS file gets included into a Makefile so that when I call make install the paths are created and built applications and conf files copied appropriately.
Now I also have a conf file which I want to use as a template.
Say the template contains lines like
LogFile=$(LOG_DIR)/myapp.log
...
Then generate a destination conf that would have
LogFile=/var/log/myapp.log
...
etc
I think this can be done with a sed script, but I'm not very familiar with sed and regular expression syntax. I will accept a shell script version too.
You should definitely go with autoconf here, whose very job is to do this. You'll have to write a conf.in file, wherein all substitutions are marked with #'s, e.g.
prefix=#prefix#
bindir=#bindir#
and write up a configure.ac, which is a shell script that will perform these substitutions for you and create conf. conf is subsequently included in the Makefile. I'd even recommend using a Makefile.in file, i.e. including your snippet in the Makefile.
If you keep to the standard path names, your configure.ac is a four-liner and has the added advantage of being GNU compatible (easy to understand & use).
You may want to consider using m4 as a simple template language instead.
I just setup Webby/Compass integration.
(https://github.com/Compass/compass/wiki/webby-integration)
Where do I put my Compass/Sass source files, and in what directory do they get
output as stylesheets?
You can put your SASS files wherever you want (under the 'content/' directory). So if the directory containing your CSS files is 'content/css', then put them there.
The only important thing is that you set the metadata part correctly, at the top of the SASS file itself. Like this:
$ cat content/css/site.sass
---
filter: sass
extension: css
layout: nil
---
[..cut..]
It looks like you can set the source-file yourself, from the documentation:
Compass.configuration do |config|
config.project_path = File.dirname(__FILE__)
config.sass_dir = File.join('src', 'stylesheets' )
end
It looks like it defaults to "src/stylesheets". When you build it it will probably get rendered to "output/css/" but I never used webby myself so im not 100% sure.
Okay found it in this repository
Apparently it belongs in the ./content/stylesheets directory of your webby project, and is output to the ./output/stylesheets directory.
What perplexes me is "why" it works this way. Why File.join? It looks like the default "src" is being replaced by "stylesheets" rather than joining a new string. Curious.