Chef: How to insert or append a line to a file

When using chef, I have often faced the problem of having to insert a line into an existing file.
The way I solved this before, was to use bash.
bash "insert_line" do
  user "root"
  code <<-EOS
  echo "" >> /etc/hosts
  not_if "grep -q /etc/hosts"
The Chef (or better the Ruby) way to do this is the following:
ruby_block "insert_line" do
  block do
    file ="/etc/hosts")
    file.insert_line_if_no_match("/", "")
Now this big question is, which is better or more readible. I guess this depends if you are more familiar with shell or ruby scripting.
One advantage of the ruby way is that the Chef::Util::FileEdit class offers a couple of other possibilities to manipulate files.
For example:
  • insert_line_if_no_match
  • search_file_delete
  • search_file_delete_line
  • search_file_replace
  • search_file_replace_line
Tagged , ,

Deployment Automation

Everyone is talking about Continuous Delivery and DevOps these days. An elemental part of this is the move towards automation of recurring tasks that have been performed manually in many businesses in the past. Especially comprehensive deployment automation is one of the most desirable goals in this methodology.

The software build process is widely automized nowadays thanks to tools like Maven or Ant and Continuous Integration servers like Jenkins, TeamCity or GO. The Internet provides plenty of good technical instructions about how to setup and run these tools. But when it comes to the last mile, the actual deployment process, most literature doesn’t go into much detail about best practices and tools to use.

Currently I am trying to dig deeper into this field, and I’d like to share my learnings. The tools that support automated deployments are also called command dispatching frameworks.  The ones I run into the most are (this list is not supposed to be complete):

Within the next days I will try to gather more information about these tools. I will not be capable to go into detail with all of them, but I will share the experiences I’ve made.

Tagged , ,