Make it easier to specify tasks to run as root #2

Open
cespare opened this Issue May 10, 2012 · 0 comments

Comments

Projects
None yet
1 participant
Collaborator

cespare commented May 10, 2012

Here's a snippet from a Terraform config I just wrote:

ensure_run_once("nginx directories have correct permissions") do
  shell "sudo chgrp admin -R /etc/nginx/sites-available", :silent => true
  shell "sudo chmod g+w -R /etc/nginx/sites-available", :silent => true
  shell "sudo chgrp admin -R /etc/nginx/sites-enabled", :silent => true
  shell "sudo chmod g+w -R /etc/nginx/sites-enabled", :silent => true
end
ensure_file("config/system_setup_files/nginx_bill", "/etc/nginx/sites-available/bill") do
  shell "cd /etc/nginx/sites-enabled && ln -fns ../sites-available/bill ./"
  shell "sudo /etc/init.d/nginx restart"
end

This is a pattern I've run into more than once, and Terraform should provide helpers to make this less verbose. For starters, it would be useful to have an ensure_permissions helper (perhaps that should be a separate ticket). However, in this case, we don't really need to give our deploy user access to the nginx directories. That stuff should really just be done as root.

One way I thought of is to have a helper that makes all dependencies defined within it be run as root. Imagine something like this:

sudo do
  ensure_file("config/system_setup_files/nginx_bill", "/etc/nginx/sites-available/bill") do
    shell "cd /etc/nginx/sites-enabled && ln -fns ../sites-available/bill ./"
    shell "/etc/init.d/nginx restart"
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment