capstrap 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.markdown CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.4.1
2
+
3
+ * Add hostname task and --domainname flag.
4
+ * Fix bug where rvm default@global is checked for chef gem.
1
5
  # 0.4.0
2
6
 
3
7
  * Tweak RVM ubuntu package dependencies.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capstrap (0.3.3)
4
+ capstrap (0.4.0)
5
5
  capistrano (~> 2.5.19)
6
6
  thor (~> 0.14.3)
7
7
 
data/README.markdown CHANGED
@@ -75,9 +75,9 @@ To save config options to a yaml file to be read by capstrap:
75
75
  config-rake-update: true
76
76
  END_OF_CAPSTRAPRC
77
77
 
78
- To set the remote hostname, use the --hostname flag:
78
+ To set the remote hostname and domain name, use the --hostname and --domainname flags:
79
79
 
80
- capstrap solo root@zland --hostname=zland
80
+ capstrap solo root@zland --hostname=zland --hostname=example.com
81
81
 
82
82
  To get more help:
83
83
 
@@ -83,7 +83,7 @@ end
83
83
  # Checks if the chef gem is installed on the remote host.
84
84
  #
85
85
  def chef_installed?
86
- cmd_if %{rvm use #{ruby}@global >/dev/null && gem list --no-versions | grep -q "^chef$" >/dev/null}, true
86
+ cmd_if %{rvm use #{ruby} >/dev/null && gem list --no-versions | grep -q "^chef$" >/dev/null}, true
87
87
  end
88
88
 
89
89
 
@@ -109,6 +109,35 @@ def hostname_correct?(host_name)
109
109
  host_name == capture(%{hostname}).chomp
110
110
  end
111
111
 
112
+ ##
113
+ # Checks if the full qualified domain name is current and correct.
114
+ #
115
+ # @param [String] ip address of host
116
+ # @param [String] desired host name
117
+ # @param [String] desired domain name
118
+ def fqdn_correct?(host_name, domain_name, ip_addr)
119
+ cmd_if %{egrep -q '^#{ip_addr}[[:space:]]+#{host_name}.#{domain_name}' /etc/hosts >/dev/null}
120
+ end
121
+
122
+ ##
123
+ # Retrieve the primary IP address of the host.
124
+ #
125
+ def fetch_primary_ip_address
126
+ capture(<<-GETADDR, :shell => "bash").chomp
127
+ _if="$(netstat -nr | grep ^0\.0\.0\.0 | awk '{print $8}')";
128
+ _ip="$(/sbin/ifconfig $_if | \
129
+ grep '^[[:space:]]*inet ' | awk '{print $2}' | \
130
+ awk -F':' '{print $2}')";
131
+
132
+ if [ -z "$_ip" -o "$_ip" == "" ] ; then
133
+ echo "";
134
+ return 10;
135
+ else
136
+ echo $_ip;
137
+ fi
138
+ GETADDR
139
+ end
140
+
112
141
  def update_cmd
113
142
  if cookbooks_rake_update
114
143
  %{rake update}
@@ -8,9 +8,15 @@ module Capstrap
8
8
 
9
9
  desc "Sets the hostname."
10
10
  task :set_hostname do
11
- unless hostname_correct?(host_name)
11
+ if exists?(:host_name)
12
+ hname = fetch(:host_name)
13
+ else
14
+ hname = capture(%{hostname}).chomp
15
+ end
16
+
17
+ unless hostname_correct?(hname)
12
18
  cmd = [
13
- %{echo "#{host_name}" > /etc/hostname},
19
+ %{echo "#{hname}" > /etc/hostname},
14
20
  %{chown root:root /etc/hostname},
15
21
  %{chmod 0644 /etc/hostname},
16
22
  %{start hostname}
@@ -18,6 +24,37 @@ module Capstrap
18
24
  run cmd.join(" && ")
19
25
  end
20
26
  end
27
+
28
+ desc "Sets the full qualified domain name."
29
+ task :set_fqdn do
30
+ begin
31
+ current_fqdn = capture(%{hostname -f}).chomp
32
+ rescue
33
+ current_fqdn = "fubarname.fubardomain"
34
+ end
35
+
36
+ if exists?(:host_name)
37
+ hname = fetch(:host_name)
38
+ else
39
+ hname = current_fqdn.split('.').shift
40
+ end
41
+
42
+ if exists?(:domain_name)
43
+ dname = fetch(:domain_name)
44
+ else
45
+ dname = current_fqdn.split('.').drop(1).join('.')
46
+ end
47
+
48
+ unless fqdn_correct?(hname, dname, "127.0.1.1")
49
+ run <<-UPDATE_HOSTS
50
+ if egrep -q '^127.0.1.1[[:space:]]' /etc/hosts >/dev/null ; then
51
+ perl -pi -e 's|^(127.0.1.1[[:space:]]+).*$|\$1#{hname}.#{dname} #{hname}|' /etc/hosts;
52
+ else
53
+ perl -pi -e 's|^(127\.0\.0\.1[[:space:]]+.*)$|\$1\n127.0.1.1 #{hname}.#{dname} #{hname}|' /etc/hosts;
54
+ fi;
55
+ UPDATE_HOSTS
56
+ end
57
+ end
21
58
  end
22
59
  end
23
60
  end
data/lib/capstrap/cli.rb CHANGED
@@ -12,6 +12,15 @@ module Capstrap
12
12
  puts "capstrap v#{Capstrap::VERSION}"
13
13
  end
14
14
 
15
+ desc "hostname HOST", "Sets the FQDN on remote SSH host HOST"
16
+ def hostname(ssh_host)
17
+ track_time do
18
+ @ssh_host = ssh_host
19
+ setup_config options
20
+ exec_hostname
21
+ end
22
+ end
23
+
15
24
  desc "ruby HOST", "Install an RVM ruby on remote SSH host HOST"
16
25
  def ruby(ssh_host)
17
26
  track_time do
@@ -59,7 +68,15 @@ module Capstrap
59
68
  end
60
69
  end
61
70
 
62
- [:ruby, :chef, :solo, :execute, :update].each do |task|
71
+ [:hostname, :ruby, :chef, :solo, :execute, :update].each do |task|
72
+ method_option "hostname", :for => task, :type => :string,
73
+ :desc => "Desired name of host.",
74
+ :aliases => "-h"
75
+
76
+ method_option "domainname", :for => task, :type => :string,
77
+ :desc => "Desired domain name of host.",
78
+ :aliases => "-d"
79
+
63
80
  method_option "config", :for => task, :type => :string,
64
81
  :desc => "Read from alternative configuration.",
65
82
  :default => File.join(ENV['HOME'], ".capstraprc"),
@@ -68,10 +85,6 @@ module Capstrap
68
85
  method_option "ruby", :for => task, :type => :string,
69
86
  :desc => "Version of ruby to install.",
70
87
  :default => "ree-1.8.7"
71
-
72
- method_option "hostname", :for => task, :type => :string,
73
- :desc => "Desired name of host.",
74
- :aliases => "-h"
75
88
  end
76
89
 
77
90
  [:chef, :solo, :execute, :update].each do |task|
@@ -148,12 +161,15 @@ module Capstrap
148
161
  end
149
162
 
150
163
  def exec_hostname
151
- if config.exists?(:host_name)
152
- config.find_and_execute_task "hostname:set_hostname"
153
- end
164
+ exec_fqdn
165
+ config.find_and_execute_task "hostname:set_hostname"
154
166
  @ran_exec_hostname = true
155
167
  end
156
168
 
169
+ def exec_fqdn
170
+ config.find_and_execute_task "hostname:set_fqdn"
171
+ end
172
+
157
173
  def config
158
174
  @config ||= prep_config
159
175
  end
@@ -188,7 +204,8 @@ module Capstrap
188
204
  {:sym => :cookbooks_path, :opt => "cookbooks-path"},
189
205
  {:sym => :config_repo, :opt => "config-repo"},
190
206
  {:sym => :config_path, :opt => "config-path"},
191
- {:sym => :host_name, :opt => "hostname"}
207
+ {:sym => :host_name, :opt => "hostname"},
208
+ {:sym => :domain_name, :opt => "domainname"}
192
209
  ].each do |var|
193
210
  config.set(var[:sym], options[var[:opt]]) if options[var[:opt]]
194
211
  end
@@ -1,3 +1,3 @@
1
1
  module Capstrap
2
- VERSION = "0.4.0"
2
+ VERSION = "0.4.1"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capstrap
3
3
  version: !ruby/object:Gem::Version
4
- hash: 15
4
+ hash: 13
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 4
9
- - 0
10
- version: 0.4.0
9
+ - 1
10
+ version: 0.4.1
11
11
  platform: ruby
12
12
  authors:
13
13
  - Fletcher Nichol
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-21 00:00:00 -07:00
18
+ date: 2011-01-23 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency