forked from mdespuits/capistrano-recipes
-
Notifications
You must be signed in to change notification settings - Fork 3
/
http_proxy.rb
88 lines (59 loc) · 1.82 KB
/
http_proxy.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
=begin rdoc
In case when environment has only one GW to access the internet, this
recipe can be used to setup HTTP proxy server and configure all other
hosts (clients here) to use proxy for internet connection.
In this case order is important since clients can not bootstrapped
unless proxy is setup and client is configured. Order of tasks is like
following:
Proxy server
-----------
- sudo install and configure
- bootstrap
- add epel repository
- install tinyproxy
After server setup finished can start with clients
Client
-----------
- configure http proxy
The rest:
- sudo install
- bootstrap
- ...
All this better done in setup task. Main `deploy.rb` should have
something like:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ruby
task :setup do
top.http_proxy.server
top.http_proxy.client
end
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
=end
set_default :proxy_port, 8888
namespace :http_proxy do
desc <<EOF
Configure host as client of HTTP proxy"
EOF
task :client, :except => { :roles => 'proxy' } do
set :proxy_host, find_servers(:roles => 'proxy').first # Should be only one proxy
next if proxy_host.nil?
set :client_hosts, find_servers - [proxy_host]
template "http_proxy.sh.erb", "/tmp/http_proxy.sh"
sudo "mv -f /tmp/http_proxy.sh /etc/profile.d/http_proxy.sh || true", shell: :bash
end
task :disable do
sudo "rm -f /etc/profile.d/http_proxy.sh || true", shell: :bash
end
desc <<EOF
Bootstrap and configure host as HTTP proxy"
EOF
task :server do
set :only_hosts, find_servers(roles: :proxy)
top.prerequisites.install.sudo
top.prerequisites.configure.sudo
top.chefsolo.deploy
top.chefsolo.roles
unset :only_hosts
puts "################################## DONE PROXY ################################ "
end
end
before 'deploy', 'http_proxy:client'