- From: David Montgomery <
>
- To:
- Subject: [chef] How ---- in a pain free method - to get the public ip address on ec2
- Date: Wed, 13 Aug 2014 09:55:09 +0800
Hi,
I am having a very hard time getting the public ip address on ec2
1) the first recipes creates these resources
directory "/etc/chef/ohai/hints" do
owner "root"
group "root"
recursive true
action :create
end
file "/etc/chef/ohai/hints/ec2.json" do
owner "root"
group "root"
action :create
end
2) In another recipe later down the line I get the ip address
if File.exists?("/etc/chef/ohai/hints/ec2.json")
ipaddress = node['ec2']['public_ipv4']
file "/tmp/public" do
owner "root"
group "root"
mode "0755"
content "#{ipaddress}"
action :create
end
end
3) Wowee.....the file is not created. Why does this happen?
4) And if I use this instead I get the below without checking for the existince of /etc/chef/ohai/hints/ec2.json
ipaddress = node['ec2']['public_ipv4']
file "/tmp/public" do
owner "root"
group "root"
mode "0755"
content "#{ipaddress}"
action :create
end
================================================================================
Recipe Compile Error in /var/chef/cache/cookbooks/cloudera/recipes/hostname.rb
================================================================================
NoMethodError
-------------
undefined method `[]' for nil:NilClass
Cookbook Trace:
---------------
/var/chef/cache/cookbooks/cloudera/recipes/hostname.rb:17:in `from_file'
Relevant File Content:
----------------------
/var/chef/cache/cookbooks/cloudera/recipes/hostname.rb:
17>> ipaddress = node['ec2']['public_ipv4']
18: file "/tmp/public" do
19: owner "root"
20: group "root"
21: mode "0755"
22: content "#{ipaddress}"
23: action :create
24: end
[2014-08-13T01:51:21+00:00] ERROR: Running exception handlers
[2014-08-13T01:51:21+00:00] ERROR: Creating JSON exception report
[2014-08-13T01:51:21+00:00] ERROR: Exception handlers complete
- [chef] How ---- in a pain free method - to get the public ip address on ec2, David Montgomery, 08/12/2014
Archive powered by MHonArc 2.6.16.