Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

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

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

cespare opened this issue May 10, 2012 · 0 comments

Comments

@cespare
Copy link
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
Projects
None yet
Development

No branches or pull requests

1 participant