rubber 1.2.1 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG +8 -0
 - data/VERSION +1 -1
 - data/generators/vulcanize/templates/apache/config/rubber/deploy-apache.rb +4 -4
 - data/generators/vulcanize/templates/base/config/rubber/deploy-setup.rb +4 -4
 - data/generators/vulcanize/templates/base/config/rubber/rubber-dns.yml +0 -1
 - data/generators/vulcanize/templates/base/config/rubber/rubber.yml +4 -4
 - data/generators/vulcanize/templates/complete_mongrel_mysql/config/rubber/role/haproxy/haproxy-mongrel.conf +2 -2
 - data/generators/vulcanize/templates/complete_passenger_mysql/config/rubber/role/haproxy/haproxy-passenger.conf +1 -1
 - data/generators/vulcanize/templates/cruise/config/rubber/deploy-cruise.rb +2 -2
 - data/generators/vulcanize/templates/haproxy/config/rubber/deploy-haproxy.rb +4 -4
 - data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslog-haproxy.conf +8 -3
 - data/generators/vulcanize/templates/haproxy/config/rubber/role/haproxy/syslogd-default.conf +4 -0
 - data/generators/vulcanize/templates/jetty/config/rubber/deploy-jetty.rb +4 -4
 - data/generators/vulcanize/templates/mongrel/config/rubber/deploy-mongrel.rb +4 -4
 - data/generators/vulcanize/templates/monit/config/rubber/common/monit.conf +0 -1
 - data/generators/vulcanize/templates/monit/config/rubber/deploy-monit.rb +4 -3
 - data/generators/vulcanize/templates/munin/config/rubber/deploy-munin.rb +3 -3
 - data/generators/vulcanize/templates/munin/config/rubber/role/web_tools/munin-plugins.conf +1 -1
 - data/generators/vulcanize/templates/mysql/config/rubber/deploy-mysql.rb +106 -8
 - data/generators/vulcanize/templates/mysql/config/rubber/role/db/apparmor-mysql.conf +46 -0
 - data/generators/vulcanize/templates/mysql/config/rubber/role/db/my.cnf +2 -6
 - data/generators/vulcanize/templates/mysql/config/rubber/rubber-mysql.yml +1 -1
 - data/generators/vulcanize/templates/nginx/config/rubber/deploy-nginx.rb +4 -4
 - data/generators/vulcanize/templates/passenger/config/rubber/deploy-passenger.rb +1 -1
 - data/generators/vulcanize/templates/passenger/config/rubber/rubber-passenger.yml +1 -1
 - data/generators/vulcanize/templates/redis/config/rubber/deploy-redis.rb +5 -5
 - data/generators/vulcanize/templates/resque/config/rubber/deploy-resque.rb +1 -1
 - data/generators/vulcanize/templates/sphinx/config/rubber/deploy-sphinx.rb +7 -6
 - data/lib/rubber/dns/zerigo.rb +59 -124
 - data/lib/rubber/environment.rb +5 -5
 - data/lib/rubber/generator.rb +29 -21
 - data/lib/rubber/recipes/rubber/deploy.rb +2 -2
 - data/lib/rubber/recipes/rubber/instances.rb +3 -0
 - data/lib/rubber/recipes/rubber/setup.rb +74 -46
 - data/lib/rubber/recipes/rubber/utils.rb +2 -2
 - data/lib/rubber/recipes/rubber/volumes.rb +4 -4
 - data/test/generator_test.rb +44 -0
 - data/test/test_helper.rb +6 -0
 - data/test/zerigo_test.rb +87 -0
 - metadata +20 -6
 
| 
         @@ -0,0 +1,46 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            <%
         
     | 
| 
      
 2 
     | 
    
         
            +
              @path = '/etc/apparmor.d/usr.sbin.mysqld'
         
     | 
| 
      
 3 
     | 
    
         
            +
              @post = "/etc/init.d/apparmor restart"
         
     | 
| 
      
 4 
     | 
    
         
            +
              @backup = false
         
     | 
| 
      
 5 
     | 
    
         
            +
            %>
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
            #include <tunables/global>
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
            /usr/sbin/mysqld {
         
     | 
| 
      
 10 
     | 
    
         
            +
              #include <abstractions/base>
         
     | 
| 
      
 11 
     | 
    
         
            +
              #include <abstractions/nameservice>
         
     | 
| 
      
 12 
     | 
    
         
            +
              #include <abstractions/user-tmp>
         
     | 
| 
      
 13 
     | 
    
         
            +
              #include <abstractions/mysql>
         
     | 
| 
      
 14 
     | 
    
         
            +
              #include <abstractions/winbind>
         
     | 
| 
      
 15 
     | 
    
         
            +
             
     | 
| 
      
 16 
     | 
    
         
            +
              capability dac_override,
         
     | 
| 
      
 17 
     | 
    
         
            +
              capability sys_resource,
         
     | 
| 
      
 18 
     | 
    
         
            +
              capability setgid,
         
     | 
| 
      
 19 
     | 
    
         
            +
              capability setuid,
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
              network tcp,
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
              /etc/hosts.allow r,
         
     | 
| 
      
 24 
     | 
    
         
            +
              /etc/hosts.deny r,
         
     | 
| 
      
 25 
     | 
    
         
            +
             
     | 
| 
      
 26 
     | 
    
         
            +
              /etc/mysql/*.pem r,
         
     | 
| 
      
 27 
     | 
    
         
            +
              /etc/mysql/conf.d/ r,
         
     | 
| 
      
 28 
     | 
    
         
            +
              /etc/mysql/conf.d/* r,
         
     | 
| 
      
 29 
     | 
    
         
            +
              /etc/mysql/my.cnf r,
         
     | 
| 
      
 30 
     | 
    
         
            +
              /usr/sbin/mysqld mr,
         
     | 
| 
      
 31 
     | 
    
         
            +
              /usr/share/mysql/** r,
         
     | 
| 
      
 32 
     | 
    
         
            +
              /var/log/mysql.log rw,
         
     | 
| 
      
 33 
     | 
    
         
            +
              /var/log/mysql.err rw,
         
     | 
| 
      
 34 
     | 
    
         
            +
              /var/lib/mysql/ r,
         
     | 
| 
      
 35 
     | 
    
         
            +
              /var/lib/mysql/** rwk,
         
     | 
| 
      
 36 
     | 
    
         
            +
              /var/log/mysql/ r,
         
     | 
| 
      
 37 
     | 
    
         
            +
              /var/log/mysql/* rw,
         
     | 
| 
      
 38 
     | 
    
         
            +
              /var/run/mysqld/mysqld.pid w,
         
     | 
| 
      
 39 
     | 
    
         
            +
              /var/run/mysqld/mysqld.sock w,
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
              /sys/devices/system/cpu/ r,
         
     | 
| 
      
 42 
     | 
    
         
            +
              /sys/devices/system/cpu/** r,
         
     | 
| 
      
 43 
     | 
    
         
            +
             
     | 
| 
      
 44 
     | 
    
         
            +
              <%= rubber_env.db_root_dir %>/ r,
         
     | 
| 
      
 45 
     | 
    
         
            +
              <%= rubber_env.db_root_dir %>/** rwk,
         
     | 
| 
      
 46 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -102,12 +102,8 @@ expire_logs_days  = 10 
     | 
|
| 
       102 
102 
     | 
    
         
             
            max_binlog_size         = 100M
         
     | 
| 
       103 
103 
     | 
    
         
             
            #binlog_do_db   = include_database_name
         
     | 
| 
       104 
104 
     | 
    
         
             
            #binlog_ignore_db = include_database_name
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
             
     | 
| 
       107 
     | 
    
         
            -
            #
         
     | 
| 
       108 
     | 
    
         
            -
            # Using BerkeleyDB is now discouraged as its support will cease in 5.1.12.
         
     | 
| 
       109 
     | 
    
         
            -
            skip-bdb
         
     | 
| 
       110 
     | 
    
         
            -
            #
         
     | 
| 
      
 105 
     | 
    
         
            +
             
     | 
| 
      
 106 
     | 
    
         
            +
             
     | 
| 
       111 
107 
     | 
    
         
             
            # * InnoDB
         
     | 
| 
       112 
108 
     | 
    
         
             
            #
         
     | 
| 
       113 
109 
     | 
    
         
             
            # InnoDB is enabled by default with a 10MB datafile in /var/lib/mysql/.
         
     | 
| 
         @@ -9,10 +9,10 @@ namespace :rubber do 
     | 
|
| 
       9 
9 
     | 
    
         
             
                # rubber auto-roles don't get defined till after all tasks are defined
         
     | 
| 
       10 
10 
     | 
    
         
             
                on :load do
         
     | 
| 
       11 
11 
     | 
    
         
             
                  rubber.serial_task self, :serial_restart, :roles => :nginx do
         
     | 
| 
       12 
     | 
    
         
            -
                     
     | 
| 
      
 12 
     | 
    
         
            +
                    sudo "/etc/init.d/nginx restart"
         
     | 
| 
       13 
13 
     | 
    
         
             
                  end
         
     | 
| 
       14 
14 
     | 
    
         
             
                  rubber.serial_task self, :serial_reload, :roles => :nginx do
         
     | 
| 
       15 
     | 
    
         
            -
                     
     | 
| 
      
 15 
     | 
    
         
            +
                    sudo "sh -c 'if ! ps ax | grep -v grep | grep -c nginx &> /dev/null; then /etc/init.d/nginx start; else /etc/init.d/nginx reload; fi'"
         
     | 
| 
       16 
16 
     | 
    
         
             
                  end
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
         @@ -22,12 +22,12 @@ namespace :rubber do 
     | 
|
| 
       22 
22 
     | 
    
         | 
| 
       23 
23 
     | 
    
         
             
                desc "Stops the nginx web server"
         
     | 
| 
       24 
24 
     | 
    
         
             
                task :stop, :roles => :nginx, :on_error => :continue do
         
     | 
| 
       25 
     | 
    
         
            -
                   
     | 
| 
      
 25 
     | 
    
         
            +
                  sudo "/etc/init.d/nginx stop"
         
     | 
| 
       26 
26 
     | 
    
         
             
                end
         
     | 
| 
       27 
27 
     | 
    
         | 
| 
       28 
28 
     | 
    
         
             
                desc "Starts the nginx web server"
         
     | 
| 
       29 
29 
     | 
    
         
             
                task :start, :roles => :nginx do
         
     | 
| 
       30 
     | 
    
         
            -
                   
     | 
| 
      
 30 
     | 
    
         
            +
                  sudo "/etc/init.d/nginx start"
         
     | 
| 
       31 
31 
     | 
    
         
             
                end
         
     | 
| 
       32 
32 
     | 
    
         | 
| 
       33 
33 
     | 
    
         
             
                desc "Restarts the nginx web server"
         
     | 
| 
         @@ -18,7 +18,7 @@ namespace :rubber do 
     | 
|
| 
       18 
18 
     | 
    
         
             
                after "rubber:setup_app_permissions", "rubber:passenger:setup_passenger_permissions"
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
20 
     | 
    
         
             
                task :setup_passenger_permissions, :roles => :passenger do
         
     | 
| 
       21 
     | 
    
         
            -
                   
     | 
| 
      
 21 
     | 
    
         
            +
                  sudo "chown #{rubber_env.app_user}:#{rubber_env.app_user} #{current_path}/config/environment.rb"
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                # passenger depends on apache for start/stop/restart, just need these defined
         
     | 
| 
         @@ -8,27 +8,27 @@ namespace :rubber do 
     | 
|
| 
       8 
8 
     | 
    
         
             
                after "rubber:install_packages", "rubber:redis:custom_install"
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
                task :custom_install, :roles => :redis do
         
     | 
| 
       11 
     | 
    
         
            -
                  custom_package('http://ftp.us.debian.org/debian/pool/main/r/redis/', 'redis-server', '1.2. 
     | 
| 
      
 11 
     | 
    
         
            +
                  custom_package('http://ftp.us.debian.org/debian/pool/main/r/redis/', 'redis-server', '1.2.5-1', '! -x /usr/bin/redis-server')
         
     | 
| 
       12 
12 
     | 
    
         
             
                end
         
     | 
| 
       13 
13 
     | 
    
         | 
| 
       14 
14 
     | 
    
         
             
                desc "Stops the redis server"
         
     | 
| 
       15 
15 
     | 
    
         
             
                task :stop, :roles => :redis, :on_error => :continue do
         
     | 
| 
       16 
     | 
    
         
            -
                   
     | 
| 
      
 16 
     | 
    
         
            +
                  sudo "/etc/init.d/redis-server stop"
         
     | 
| 
       17 
17 
     | 
    
         
             
                end
         
     | 
| 
       18 
18 
     | 
    
         | 
| 
       19 
19 
     | 
    
         
             
                desc "Starts the redis server"
         
     | 
| 
       20 
20 
     | 
    
         
             
                task :start, :roles => :redis do
         
     | 
| 
       21 
     | 
    
         
            -
                   
     | 
| 
      
 21 
     | 
    
         
            +
                  sudo "/etc/init.d/redis-server start"
         
     | 
| 
       22 
22 
     | 
    
         
             
                end
         
     | 
| 
       23 
23 
     | 
    
         | 
| 
       24 
24 
     | 
    
         
             
                desc "Restarts the redis server"
         
     | 
| 
       25 
25 
     | 
    
         
             
                task :restart, :roles => :redis do
         
     | 
| 
       26 
     | 
    
         
            -
                   
     | 
| 
      
 26 
     | 
    
         
            +
                  sudo "/etc/init.d/redis-server restart"
         
     | 
| 
       27 
27 
     | 
    
         
             
                end
         
     | 
| 
       28 
28 
     | 
    
         | 
| 
       29 
29 
     | 
    
         
             
                desc "Reloads the redis server"
         
     | 
| 
       30 
30 
     | 
    
         
             
                task :reload, :roles => :redis do
         
     | 
| 
       31 
     | 
    
         
            -
                   
     | 
| 
      
 31 
     | 
    
         
            +
                  sudo "/etc/init.d/redis-server restart"
         
     | 
| 
       32 
32 
     | 
    
         
             
                end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
              end
         
     | 
| 
         @@ -32,7 +32,7 @@ namespace :rubber do 
     | 
|
| 
       32 
32 
     | 
    
         
             
                after "rubber:setup_app_permissions", "rubber:resque:setup_resque_permissions"
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
34 
     | 
    
         
             
                task :setup_resque_permissions, :roles => :resque do
         
     | 
| 
       35 
     | 
    
         
            -
                   
     | 
| 
      
 35 
     | 
    
         
            +
                  sudo "chown -R #{rubber_env.app_user}:#{rubber_env.app_user} #{rubber_env.resque_web_dir}/config.ru"
         
     | 
| 
       36 
36 
     | 
    
         
             
                end
         
     | 
| 
       37 
37 
     | 
    
         | 
| 
       38 
38 
     | 
    
         
             
              end
         
     | 
| 
         @@ -18,7 +18,7 @@ namespace :rubber do 
     | 
|
| 
       18 
18 
     | 
    
         
             
                task :custom_install, :roles => :sphinx do
         
     | 
| 
       19 
19 
     | 
    
         
             
                  # install sphinx from source
         
     | 
| 
       20 
20 
     | 
    
         
             
                  ver = "0.9.8.1"
         
     | 
| 
       21 
     | 
    
         
            -
                  rubber. 
     | 
| 
      
 21 
     | 
    
         
            +
                  rubber.sudo_script 'install_sphinx', <<-ENDSCRIPT
         
     | 
| 
       22 
22 
     | 
    
         
             
                    # check if already installed
         
     | 
| 
       23 
23 
     | 
    
         
             
                    if [ -x /usr/local/bin/searchd ]
         
     | 
| 
       24 
24 
     | 
    
         
             
                      then echo 'Found sphinx searchd on system'
         
     | 
| 
         @@ -60,19 +60,20 @@ namespace :rubber do 
     | 
|
| 
       60 
60 
     | 
    
         
             
                desc "Do sphinx setup tasks"
         
     | 
| 
       61 
61 
     | 
    
         
             
                task :setup, :roles => :sphinx do
         
     | 
| 
       62 
62 
     | 
    
         
             
                  # Setup links to sphinx config/index as they need to persist between deploys
         
     | 
| 
       63 
     | 
    
         
            -
                   
     | 
| 
       64 
     | 
    
         
            -
                   
     | 
| 
      
 63 
     | 
    
         
            +
                  sudo "mkdir -p #{sphinx_root} #{sphinx_root}/config #{sphinx_root}/db"
         
     | 
| 
      
 64 
     | 
    
         
            +
                  sudo "chown -R #{runner}:#{runner} #{sphinx_root}"
         
     | 
| 
       65 
65 
     | 
    
         
             
                end
         
     | 
| 
       66 
66 
     | 
    
         | 
| 
       67 
67 
     | 
    
         
             
                desc "Setup paths for sphinx runtime"
         
     | 
| 
       68 
68 
     | 
    
         
             
                task :config_dir, :roles => :sphinx do
         
     | 
| 
       69 
     | 
    
         
            -
                   
     | 
| 
      
 69 
     | 
    
         
            +
                  sudo "rm -rf #{current_path}/sphinx"
         
     | 
| 
      
 70 
     | 
    
         
            +
                  sudo "ln -sf #{sphinx_root} #{current_path}/sphinx"
         
     | 
| 
       70 
71 
     | 
    
         
             
                end
         
     | 
| 
       71 
72 
     | 
    
         | 
| 
       72 
73 
     | 
    
         
             
                # runs the given ultrasphinx rake tasks
         
     | 
| 
       73 
74 
     | 
    
         
             
                def run_sphinx task
         
     | 
| 
       74 
     | 
    
         
            -
                  cmd = "cd #{current_path} && sudo -u #{runner} RAILS_ENV=#{RUBBER_ENV} rake #{task}"
         
     | 
| 
       75 
     | 
    
         
            -
                   
     | 
| 
      
 75 
     | 
    
         
            +
                  cmd = "sh -c 'cd #{current_path} && sudo -u #{runner} RAILS_ENV=#{RUBBER_ENV} rake #{task}'"
         
     | 
| 
      
 76 
     | 
    
         
            +
                  sudo cmd
         
     | 
| 
       76 
77 
     | 
    
         
             
                end
         
     | 
| 
       77 
78 
     | 
    
         | 
| 
       78 
79 
     | 
    
         | 
    
        data/lib/rubber/dns/zerigo.rb
    CHANGED
    
    | 
         @@ -1,170 +1,105 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            require 'rubygems'
         
     | 
| 
       2 
     | 
    
         
            -
            require ' 
     | 
| 
      
 2 
     | 
    
         
            +
            require 'zerigo_dns'
         
     | 
| 
       3 
3 
     | 
    
         | 
| 
       4 
4 
     | 
    
         
             
            module Rubber
         
     | 
| 
       5 
5 
     | 
    
         
             
              module Dns
         
     | 
| 
       6 
6 
     | 
    
         | 
| 
      
 7 
     | 
    
         
            +
                class Zerigo < Base
         
     | 
| 
       7 
8 
     | 
    
         | 
| 
       8 
     | 
    
         
            -
             
     | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
       10 
     | 
    
         
            -
                  format :xml
         
     | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
       12 
     | 
    
         
            -
                  @@zones = {}
         
     | 
| 
       13 
     | 
    
         
            -
                  def self.get_zone(domain, provider_env)
         
     | 
| 
       14 
     | 
    
         
            -
                   @@zones[domain] ||= Zone.new(provider_env.customer_id, provider_env.email, provider_env.token, domain)
         
     | 
| 
       15 
     | 
    
         
            -
                  end
         
     | 
| 
      
 9 
     | 
    
         
            +
                  def initialize(env)
         
     | 
| 
      
 10 
     | 
    
         
            +
                    super(env, "zerigo")
         
     | 
| 
       16 
11 
     | 
    
         | 
| 
       17 
     | 
    
         
            -
             
     | 
| 
       18 
     | 
    
         
            -
                     
     | 
| 
       19 
     | 
    
         
            -
                    self.class.base_uri "https://ns.zerigo.com/accounts/#{customer_id}"
         
     | 
| 
       20 
     | 
    
         
            -
                    @domain = domain
         
     | 
| 
       21 
     | 
    
         
            -
                    refresh()
         
     | 
| 
      
 12 
     | 
    
         
            +
                    ::Zerigo::DNS::Base.user = provider_env.email
         
     | 
| 
      
 13 
     | 
    
         
            +
                    ::Zerigo::DNS::Base.password = provider_env.token
         
     | 
| 
       22 
14 
     | 
    
         
             
                  end
         
     | 
| 
       23 
15 
     | 
    
         | 
| 
       24 
     | 
    
         
            -
                  def  
     | 
| 
       25 
     | 
    
         
            -
                     
     | 
| 
       26 
     | 
    
         
            -
                     
     | 
| 
       27 
     | 
    
         
            -
             
     | 
| 
       28 
     | 
    
         
            -
             
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
       30 
     | 
    
         
            -
                     
     | 
| 
       31 
     | 
    
         
            -
                     
     | 
| 
      
 16 
     | 
    
         
            +
                  def host_to_opts(host)
         
     | 
| 
      
 17 
     | 
    
         
            +
                    opts = {}
         
     | 
| 
      
 18 
     | 
    
         
            +
                    opts[:id] = host.id
         
     | 
| 
      
 19 
     | 
    
         
            +
                    opts[:host] = host.hostname || ''
         
     | 
| 
      
 20 
     | 
    
         
            +
                    opts[:type] = host.host_type
         
     | 
| 
      
 21 
     | 
    
         
            +
                    opts[:data] = host.data if host.data
         
     | 
| 
      
 22 
     | 
    
         
            +
                    opts[:ttl] = host.ttl if host.ttl
         
     | 
| 
      
 23 
     | 
    
         
            +
                    opts[:priority] = host.priority if host.priority
         
     | 
| 
      
 24 
     | 
    
         
            +
                    return opts
         
     | 
| 
       32 
25 
     | 
    
         
             
                  end
         
     | 
| 
       33 
26 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
                  def  
     | 
| 
       35 
     | 
    
         
            -
                    host =  
     | 
| 
       36 
     | 
    
         
            -
                     
     | 
| 
      
 27 
     | 
    
         
            +
                  def opts_to_host(opts, host={})
         
     | 
| 
      
 28 
     | 
    
         
            +
                    host['hostname'] = opts[:host]
         
     | 
| 
      
 29 
     | 
    
         
            +
                    host['host_type'] =  opts[:type]
         
     | 
| 
      
 30 
     | 
    
         
            +
                    host['data'] = opts[:data] if opts[:data]
         
     | 
| 
      
 31 
     | 
    
         
            +
                    host['ttl'] = opts[:ttl] if opts[:ttl]
         
     | 
| 
      
 32 
     | 
    
         
            +
                    host['priority'] = opts[:priority] if opts[:priority]
         
     | 
| 
      
 33 
     | 
    
         
            +
                    return host
         
     | 
| 
       37 
34 
     | 
    
         
             
                  end
         
     | 
| 
       38 
35 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
                  def  
     | 
| 
      
 36 
     | 
    
         
            +
                  def find_hosts(opts = {})
         
     | 
| 
      
 37 
     | 
    
         
            +
                    opts = setup_opts(opts, [:host, :domain])
         
     | 
| 
       40 
38 
     | 
    
         
             
                    result = []
         
     | 
| 
      
 39 
     | 
    
         
            +
                    zone = ::Zerigo::DNS::Zone.find_or_create(opts[:domain])
         
     | 
| 
      
 40 
     | 
    
         
            +
                    params = { :zone_id => zone.id }
         
     | 
| 
      
 41 
     | 
    
         
            +
             
     | 
| 
       41 
42 
     | 
    
         
             
                    hn = opts[:host]
         
     | 
| 
       42 
43 
     | 
    
         
             
                    ht = opts[:type]
         
     | 
| 
       43 
44 
     | 
    
         
             
                    hd = opts[:data]
         
     | 
| 
       44 
45 
     | 
    
         
             
                    has_host = hn && hn != '*'
         
     | 
| 
       45 
     | 
    
         
            -
             
     | 
| 
       46 
     | 
    
         
            -
                    url = "/zones/#{@zone['id']}/hosts.xml"
         
     | 
| 
       47 
46 
     | 
    
         
             
                    if has_host
         
     | 
| 
       48 
     | 
    
         
            -
                      url  
     | 
| 
      
 47 
     | 
    
         
            +
                      url = ""
         
     | 
| 
       49 
48 
     | 
    
         
             
                      url << "#{hn}." if hn.strip.size > 0
         
     | 
| 
       50 
     | 
    
         
            -
                      url << "#{ 
     | 
| 
      
 49 
     | 
    
         
            +
                      url << "#{opts[:domain]}"
         
     | 
| 
      
 50 
     | 
    
         
            +
                      params[:fqdn] = url
         
     | 
| 
       51 
51 
     | 
    
         
             
                    end
         
     | 
| 
       52 
     | 
    
         
            -
                    hosts = self.class.get(url)
         
     | 
| 
       53 
     | 
    
         
            -
             
     | 
| 
       54 
     | 
    
         
            -
                    # returns 404 on not found, so don't check status
         
     | 
| 
       55 
     | 
    
         
            -
                    hosts = check_status hosts unless has_host
         
     | 
| 
       56 
     | 
    
         
            -
             
     | 
| 
       57 
     | 
    
         
            -
                    hosts['hosts'].each do |h|
         
     | 
| 
       58 
     | 
    
         
            -
                      keep = true
         
     | 
| 
       59 
     | 
    
         
            -
                      if ht && h['host_type'] != ht && ht != '*'
         
     | 
| 
       60 
     | 
    
         
            -
                        keep = false
         
     | 
| 
       61 
     | 
    
         
            -
                      end
         
     | 
| 
       62 
     | 
    
         
            -
                      if hd && h['data'] != hd
         
     | 
| 
       63 
     | 
    
         
            -
                        keep = false
         
     | 
| 
       64 
     | 
    
         
            -
                      end
         
     | 
| 
       65 
     | 
    
         
            -
                      result << host_to_opts(h) if keep
         
     | 
| 
       66 
     | 
    
         
            -
                    end if hosts['hosts']
         
     | 
| 
       67 
     | 
    
         
            -
             
     | 
| 
       68 
     | 
    
         
            -
                    return result
         
     | 
| 
       69 
     | 
    
         
            -
                  end
         
     | 
| 
       70 
     | 
    
         
            -
             
     | 
| 
       71 
     | 
    
         
            -
                  def update_host(host_id, opts)
         
     | 
| 
       72 
     | 
    
         
            -
                    host = opts_to_host(opts, new_host())
         
     | 
| 
       73 
     | 
    
         
            -
                    check_status self.class.put("/zones/#{@zone['id']}/hosts/#{host_id}.xml", :body => {:host => host})
         
     | 
| 
       74 
     | 
    
         
            -
                  end
         
     | 
| 
       75 
52 
     | 
    
         | 
| 
       76 
     | 
    
         
            -
             
     | 
| 
       77 
     | 
    
         
            -
             
     | 
| 
       78 
     | 
    
         
            -
             
     | 
| 
       79 
     | 
    
         
            -
             
     | 
| 
       80 
     | 
    
         
            -
             
     | 
| 
       81 
     | 
    
         
            -
             
     | 
| 
       82 
     | 
    
         
            -
             
     | 
| 
       83 
     | 
    
         
            -
             
     | 
| 
       84 
     | 
    
         
            -
             
     | 
| 
       85 
     | 
    
         
            -
             
     | 
| 
       86 
     | 
    
         
            -
             
     | 
| 
      
 53 
     | 
    
         
            +
                    begin
         
     | 
| 
      
 54 
     | 
    
         
            +
                      hosts = ::Zerigo::DNS::Host.find(:all, :params=> params)
         
     | 
| 
      
 55 
     | 
    
         
            +
             
     | 
| 
      
 56 
     | 
    
         
            +
                      hosts.each do |h|
         
     | 
| 
      
 57 
     | 
    
         
            +
                        keep = true
         
     | 
| 
      
 58 
     | 
    
         
            +
                        if ht && h.host_type != ht && ht != '*'
         
     | 
| 
      
 59 
     | 
    
         
            +
                          keep = false
         
     | 
| 
      
 60 
     | 
    
         
            +
                        end
         
     | 
| 
      
 61 
     | 
    
         
            +
                        if hd && h.data != hd
         
     | 
| 
      
 62 
     | 
    
         
            +
                          keep = false
         
     | 
| 
      
 63 
     | 
    
         
            +
                        end
         
     | 
| 
      
 64 
     | 
    
         
            +
                        result << h if keep
         
     | 
| 
      
 65 
     | 
    
         
            +
                      end if hosts
         
     | 
| 
      
 66 
     | 
    
         
            +
                    rescue ActiveResource::ResourceNotFound => e
         
     | 
| 
       87 
67 
     | 
    
         
             
                    end
         
     | 
| 
       88 
     | 
    
         
            -
                    if ! @zone
         
     | 
| 
       89 
     | 
    
         
            -
                      zone = new_zone()
         
     | 
| 
       90 
     | 
    
         
            -
                      zone['domain'] = @domain
         
     | 
| 
       91 
     | 
    
         
            -
                      zones = check_status self.class.post('/zones.xml', :body => {:zone => zone})
         
     | 
| 
       92 
     | 
    
         
            -
                      @zone = zones['zone']
         
     | 
| 
       93 
     | 
    
         
            -
                    end
         
     | 
| 
       94 
     | 
    
         
            -
                  end
         
     | 
| 
       95 
68 
     | 
    
         | 
| 
       96 
     | 
    
         
            -
             
     | 
| 
       97 
     | 
    
         
            -
                    return @zone
         
     | 
| 
       98 
     | 
    
         
            -
                  end
         
     | 
| 
       99 
     | 
    
         
            -
             
     | 
| 
       100 
     | 
    
         
            -
                  private
         
     | 
| 
       101 
     | 
    
         
            -
             
     | 
| 
       102 
     | 
    
         
            -
                  def new_host
         
     | 
| 
       103 
     | 
    
         
            -
                    check_status(self.class.get("/zones/#{@zone['id']}/hosts/new.xml"))['host']
         
     | 
| 
       104 
     | 
    
         
            -
                  end
         
     | 
| 
       105 
     | 
    
         
            -
             
     | 
| 
       106 
     | 
    
         
            -
                  def new_zone
         
     | 
| 
       107 
     | 
    
         
            -
                    check_status(self.class.get("/zones/new.xml"))['zone']
         
     | 
| 
       108 
     | 
    
         
            -
                  end
         
     | 
| 
       109 
     | 
    
         
            -
             
     | 
| 
       110 
     | 
    
         
            -
                  def opts_to_host(opts, host={})
         
     | 
| 
       111 
     | 
    
         
            -
                    host['hostname'] = opts[:host]
         
     | 
| 
       112 
     | 
    
         
            -
                    host['host_type'] =  opts[:type]
         
     | 
| 
       113 
     | 
    
         
            -
                    host['data'] = opts[:data] if opts[:data]
         
     | 
| 
       114 
     | 
    
         
            -
                    host['ttl'] = opts[:ttl] if opts[:ttl]
         
     | 
| 
       115 
     | 
    
         
            -
                    host['priority'] = opts[:priority] if opts[:priority]
         
     | 
| 
       116 
     | 
    
         
            -
                    return host
         
     | 
| 
       117 
     | 
    
         
            -
                  end
         
     | 
| 
       118 
     | 
    
         
            -
             
     | 
| 
       119 
     | 
    
         
            -
                  def host_to_opts(host)
         
     | 
| 
       120 
     | 
    
         
            -
                    opts = {}
         
     | 
| 
       121 
     | 
    
         
            -
                    opts[:id] = host['id'] 
         
     | 
| 
       122 
     | 
    
         
            -
                    opts[:domain] = @domain
         
     | 
| 
       123 
     | 
    
         
            -
                    opts[:host] = host['hostname'] || ''
         
     | 
| 
       124 
     | 
    
         
            -
                    opts[:type] = host['host_type']
         
     | 
| 
       125 
     | 
    
         
            -
                    opts[:data] = host['data'] if host['data']
         
     | 
| 
       126 
     | 
    
         
            -
                    opts[:ttl] = host['ttl'] if host['ttl']
         
     | 
| 
       127 
     | 
    
         
            -
                    opts[:priority] = host['priority'] if host['priority']
         
     | 
| 
       128 
     | 
    
         
            -
                    return opts
         
     | 
| 
       129 
     | 
    
         
            -
                  end
         
     | 
| 
       130 
     | 
    
         
            -
                end
         
     | 
| 
       131 
     | 
    
         
            -
                
         
     | 
| 
       132 
     | 
    
         
            -
                class Zerigo < Base
         
     | 
| 
       133 
     | 
    
         
            -
             
     | 
| 
       134 
     | 
    
         
            -
                  def initialize(env)
         
     | 
| 
       135 
     | 
    
         
            -
                    super(env, "zerigo")
         
     | 
| 
      
 69 
     | 
    
         
            +
                    return result
         
     | 
| 
       136 
70 
     | 
    
         
             
                  end
         
     | 
| 
       137 
71 
     | 
    
         | 
| 
       138 
72 
     | 
    
         
             
                  def find_host_records(opts = {})
         
     | 
| 
       139 
     | 
    
         
            -
                     
     | 
| 
       140 
     | 
    
         
            -
                     
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
                    zone.find_host_records(opts)
         
     | 
| 
      
 73 
     | 
    
         
            +
                    hosts = find_hosts(opts)
         
     | 
| 
      
 74 
     | 
    
         
            +
                    result = hosts.collect {|h| host_to_opts(h).merge(:domain => opts[:domain]) }
         
     | 
| 
      
 75 
     | 
    
         
            +
                    return result
         
     | 
| 
       143 
76 
     | 
    
         
             
                  end
         
     | 
| 
       144 
77 
     | 
    
         | 
| 
       145 
78 
     | 
    
         
             
                  def create_host_record(opts = {})
         
     | 
| 
       146 
79 
     | 
    
         
             
                    opts = setup_opts(opts, [:host, :data, :domain, :type, :ttl])
         
     | 
| 
       147 
     | 
    
         
            -
                    zone = Zone. 
     | 
| 
       148 
     | 
    
         
            -
             
     | 
| 
       149 
     | 
    
         
            -
                    zone.create_host(opts)
         
     | 
| 
      
 80 
     | 
    
         
            +
                    zone = ::Zerigo::DNS::Zone.find_or_create(opts[:domain])
         
     | 
| 
      
 81 
     | 
    
         
            +
                    ::Zerigo::DNS::Host.create(opts_to_host(opts).merge(:zone_id => zone.id))
         
     | 
| 
       150 
82 
     | 
    
         
             
                  end
         
     | 
| 
       151 
83 
     | 
    
         | 
| 
       152 
84 
     | 
    
         
             
                  def destroy_host_record(opts = {})
         
     | 
| 
       153 
85 
     | 
    
         
             
                    opts = setup_opts(opts, [:host, :domain])
         
     | 
| 
       154 
     | 
    
         
            -
                    zone = Zone. 
     | 
| 
      
 86 
     | 
    
         
            +
                    zone = ::Zerigo::DNS::Zone.find_or_create(opts[:domain])
         
     | 
| 
       155 
87 
     | 
    
         | 
| 
       156 
     | 
    
         
            -
                     
     | 
| 
       157 
     | 
    
         
            -
                       
     | 
| 
      
 88 
     | 
    
         
            +
                    find_hosts(opts).each do |h|
         
     | 
| 
      
 89 
     | 
    
         
            +
                      h.destroy || raise("Failed to destroy #{h.hostname}")
         
     | 
| 
       158 
90 
     | 
    
         
             
                    end
         
     | 
| 
       159 
91 
     | 
    
         
             
                  end
         
     | 
| 
       160 
92 
     | 
    
         | 
| 
       161 
93 
     | 
    
         
             
                  def update_host_record(old_opts={}, new_opts={})
         
     | 
| 
       162 
94 
     | 
    
         
             
                    old_opts = setup_opts(old_opts, [:host, :domain])
         
     | 
| 
       163 
95 
     | 
    
         
             
                    new_opts = setup_opts(new_opts.merge(:no_defaults =>true), [])
         
     | 
| 
       164 
     | 
    
         
            -
                    zone = Zone. 
     | 
| 
      
 96 
     | 
    
         
            +
                    zone = ::Zerigo::DNS::Zone.find_or_create(old_opts[:domain])
         
     | 
| 
       165 
97 
     | 
    
         | 
| 
       166 
     | 
    
         
            -
                     
     | 
| 
       167 
     | 
    
         
            -
                       
     | 
| 
      
 98 
     | 
    
         
            +
                    find_hosts(old_opts).each do |h|
         
     | 
| 
      
 99 
     | 
    
         
            +
                      opts_to_host(new_opts).each do |k, v|
         
     | 
| 
      
 100 
     | 
    
         
            +
                        h.send("#{k}=", v)
         
     | 
| 
      
 101 
     | 
    
         
            +
                      end
         
     | 
| 
      
 102 
     | 
    
         
            +
                      h.save || raise("Failed to update host #{h.hostname}")
         
     | 
| 
       168 
103 
     | 
    
         
             
                    end
         
     | 
| 
       169 
104 
     | 
    
         
             
                  end
         
     | 
| 
       170 
105 
     | 
    
         | 
    
        data/lib/rubber/environment.rb
    CHANGED
    
    | 
         @@ -145,14 +145,14 @@ module Rubber 
     | 
|
| 
       145 
145 
     | 
    
         
             
                      global = global.clone()
         
     | 
| 
       146 
146 
     | 
    
         
             
                      role_overrides = global.delete("roles") || {}
         
     | 
| 
       147 
147 
     | 
    
         
             
                      host_overrides = global.delete("hosts") || {}
         
     | 
| 
       148 
     | 
    
         
            -
                      roles. 
     | 
| 
       149 
     | 
    
         
            -
                        role_overrides[role].each do |k, v|
         
     | 
| 
      
 148 
     | 
    
         
            +
                      Array(roles).each do |role|
         
     | 
| 
      
 149 
     | 
    
         
            +
                        Array(role_overrides[role]).each do |k, v|
         
     | 
| 
       150 
150 
     | 
    
         
             
                          global[k] = Environment.combine(global[k], v)
         
     | 
| 
       151 
     | 
    
         
            -
                        end 
     | 
| 
      
 151 
     | 
    
         
            +
                        end
         
     | 
| 
       152 
152 
     | 
    
         
             
                      end
         
     | 
| 
       153 
     | 
    
         
            -
                      host_overrides[host].each do |k, v|
         
     | 
| 
      
 153 
     | 
    
         
            +
                      Array(host_overrides[host]).each do |k, v|
         
     | 
| 
       154 
154 
     | 
    
         
             
                        global[k] = Environment.combine(global[k], v)
         
     | 
| 
       155 
     | 
    
         
            -
                      end 
     | 
| 
      
 155 
     | 
    
         
            +
                      end
         
     | 
| 
       156 
156 
     | 
    
         
             
                      return global
         
     | 
| 
       157 
157 
     | 
    
         
             
                    end
         
     | 
| 
       158 
158 
     | 
    
         | 
    
        data/lib/rubber/generator.rb
    CHANGED
    
    | 
         @@ -113,7 +113,7 @@ module Rubber 
     | 
|
| 
       113 
113 
     | 
    
         
             
                      FileUtils.mkdir_p(File.dirname(config_path)) if config_path
         
     | 
| 
       114 
114 
     | 
    
         | 
| 
       115 
115 
     | 
    
         
             
                      # Write a backup of original
         
     | 
| 
       116 
     | 
    
         
            -
                      open("#{config_path}.bak", 'w') { |f| f.write(orig) } if config_path
         
     | 
| 
      
 116 
     | 
    
         
            +
                      open("#{config_path}.bak", 'w') { |f| f.write(orig) } if config_path && config.backup
         
     | 
| 
       117 
117 
     | 
    
         | 
| 
       118 
118 
     | 
    
         
             
                      # Write out transformed file
         
     | 
| 
       119 
119 
     | 
    
         
             
                      writer = config_path || "|#{config.write_cmd}"
         
     | 
| 
         @@ -130,21 +130,23 @@ module Rubber 
     | 
|
| 
       130 
130 
     | 
    
         | 
| 
       131 
131 
     | 
    
         
             
                      # Run post transform command if needed
         
     | 
| 
       132 
132 
     | 
    
         
             
                      if config.post
         
     | 
| 
       133 
     | 
    
         
            -
                        if  
     | 
| 
       134 
     | 
    
         
            -
                          LOGGER.info(" 
     | 
| 
      
 133 
     | 
    
         
            +
                        if fake_root
         
     | 
| 
      
 134 
     | 
    
         
            +
                          LOGGER.info("Not running post command as a fake root was given: #{config.post}")
         
     | 
| 
       135 
135 
     | 
    
         
             
                        elsif no_post
         
     | 
| 
       136 
136 
     | 
    
         
             
                          LOGGER.info("Not running post command as no post specified")
         
     | 
| 
       137 
     | 
    
         
            -
                        elsif fake_root
         
     | 
| 
       138 
     | 
    
         
            -
                          LOGGER.info("Not running post command as a fake root was given: #{config.post}")
         
     | 
| 
       139 
137 
     | 
    
         
             
                        else
         
     | 
| 
       140 
     | 
    
         
            -
                           
     | 
| 
       141 
     | 
    
         
            -
             
     | 
| 
       142 
     | 
    
         
            -
             
     | 
| 
       143 
     | 
    
         
            -
             
     | 
| 
       144 
     | 
    
         
            -
             
     | 
| 
       145 
     | 
    
         
            -
             
     | 
| 
       146 
     | 
    
         
            -
             
     | 
| 
       147 
     | 
    
         
            -
                             
     | 
| 
      
 138 
     | 
    
         
            +
                          if orig != result || force
         
     | 
| 
      
 139 
     | 
    
         
            +
                            # this lets us abort a script if a command in the middle of it errors out
         
     | 
| 
      
 140 
     | 
    
         
            +
                            # stop_on_error_cmd = "function error_exit { exit 99; }; trap error_exit ERR"
         
     | 
| 
      
 141 
     | 
    
         
            +
                            config.post = "#{stop_on_error_cmd}\n#{config.post}" if stop_on_error_cmd
         
     | 
| 
      
 142 
     | 
    
         
            +
             
     | 
| 
      
 143 
     | 
    
         
            +
                            LOGGER.info{"Transformation executing post config command: #{config.post}"}
         
     | 
| 
      
 144 
     | 
    
         
            +
                            LOGGER.info `#{config.post}`
         
     | 
| 
      
 145 
     | 
    
         
            +
                            if $?.exitstatus != 0
         
     | 
| 
      
 146 
     | 
    
         
            +
                              raise "Post command failed execution:  #{config.post}"
         
     | 
| 
      
 147 
     | 
    
         
            +
                            end
         
     | 
| 
      
 148 
     | 
    
         
            +
                          else
         
     | 
| 
      
 149 
     | 
    
         
            +
                            LOGGER.info("Nothing to do, not running post command")
         
     | 
| 
       148 
150 
     | 
    
         
             
                          end
         
     | 
| 
       149 
151 
     | 
    
         
             
                        end
         
     | 
| 
       150 
152 
     | 
    
         
             
                      end
         
     | 
| 
         @@ -174,22 +176,28 @@ module Rubber 
     | 
|
| 
       174 
176 
     | 
    
         
             
                  attr_accessor :additive
         
     | 
| 
       175 
177 
     | 
    
         
             
                  # Lets one dynamically determine if a given file gets skipped during transformation
         
     | 
| 
       176 
178 
     | 
    
         
             
                  attr_accessor :skip
         
     | 
| 
      
 179 
     | 
    
         
            +
                  # Backup file when transforming, defaults to true, set to false to prevent backup
         
     | 
| 
      
 180 
     | 
    
         
            +
                  attr_accessor :backup
         
     | 
| 
       177 
181 
     | 
    
         
             
                  # use sudo to write the output file
         
     | 
| 
       178 
182 
     | 
    
         
             
                  # attr_accessor :sudo
         
     | 
| 
       179 
183 
     | 
    
         
             
                  # options passed in through code
         
     | 
| 
       180 
184 
     | 
    
         
             
                  attr_accessor :options
         
     | 
| 
       181 
185 
     | 
    
         | 
| 
      
 186 
     | 
    
         
            +
                  def initialize
         
     | 
| 
      
 187 
     | 
    
         
            +
                    @backup = true
         
     | 
| 
      
 188 
     | 
    
         
            +
                  end
         
     | 
| 
      
 189 
     | 
    
         
            +
                  
         
     | 
| 
       182 
190 
     | 
    
         
             
                  def get_binding
         
     | 
| 
       183 
191 
     | 
    
         
             
                    binding
         
     | 
| 
       184 
     | 
    
         
            -
             
     | 
| 
      
 192 
     | 
    
         
            +
                  end
         
     | 
| 
       185 
193 
     | 
    
         | 
| 
       186 
     | 
    
         
            -
             
     | 
| 
       187 
     | 
    
         
            -
             
     | 
| 
       188 
     | 
    
         
            -
             
     | 
| 
       189 
     | 
    
         
            -
             
     | 
| 
       190 
     | 
    
         
            -
             
     | 
| 
       191 
     | 
    
         
            -
             
     | 
| 
       192 
     | 
    
         
            -
             
     | 
| 
      
 194 
     | 
    
         
            +
                  def rubber_env()
         
     | 
| 
      
 195 
     | 
    
         
            +
                    Rubber::Configuration.rubber_env
         
     | 
| 
      
 196 
     | 
    
         
            +
                  end
         
     | 
| 
      
 197 
     | 
    
         
            +
             
     | 
| 
      
 198 
     | 
    
         
            +
                  def rubber_instances()
         
     | 
| 
      
 199 
     | 
    
         
            +
                    Rubber::Configuration.rubber_instances
         
     | 
| 
      
 200 
     | 
    
         
            +
                  end
         
     | 
| 
       193 
201 
     | 
    
         | 
| 
       194 
202 
     | 
    
         
             
                end
         
     | 
| 
       195 
203 
     | 
    
         |