-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchef-recipe.rb
37 lines (33 loc) · 1.11 KB
/
chef-recipe.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
# Author Shubham<[email protected]>
# assuming you already setup nginx
# And have a real-ip module loaded.
# You can verify that with nginx -V command
# Once done include this file /etc/nginx/conf.d/cfront.ipranges.conf in your nginx.conf
# Licence GPL
# You are all set
default[:config_common][:nginx_gce_cf_path]='/etc/nginx/conf.d/cfront.ipranges.conf'
service "nginx" do
action :start
end
ruby_block 'cf-ip-range-update' do
block do
require 'open-uri'
require 'json'
status=false
doc = JSON.parse(open('https://ip-ranges.amazonaws.com/ip-ranges.json').read)
f=File.open(node[:config_common][:nginx_gce_cf_path])
text = f.read
File.open(node[:config_common][:nginx_gce_cf_path],'a') do |o|
doc['prefixes'].each do |x|
if x['service'] =='CLOUDFRONT'
puts "set_real_ip_from #{x['ip_prefix']}; "
o.write("set_real_ip_from #{x['ip_prefix']}; \n")
end if !Regexp.new(Regexp.escape(x['ip_prefix'])).match(text)
end if doc
end
f.close
#print text
end
action :run
notifies :reload, 'service[nginx]'
end