Skip to content

Instantly share code, notes, and snippets.

@vinyar
Created April 13, 2017 00:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vinyar/a84df4c579f2ae3d8fd8c4d348f5d983 to your computer and use it in GitHub Desktop.
Save vinyar/a84df4c579f2ae3d8fd8c4d348f5d983 to your computer and use it in GitHub Desktop.
recipe
Note that IP address 2.2.2.2 is added as it should, but then hostname resource removes it.
Recipe: lk_base::via_hostfile
* hostsfile_entry[127.0.1.1] action create
Recipe: <Dynamically Defined Resource>
* file[/etc/hosts] action create
- update content in file /etc/hosts from 7e4391 to 6994f8
--- /etc/hosts 2017-04-13 00:12:00.526652000 +0000
+++ /etc/.chef-hosts20170413-20240-1njwh1c 2017-04-13 00:17:10.693658000 +0000
@@ -9,9 +9,9 @@
127.0.0.1 test-node localhost
127.0.1.1 local-testing.test.test local-testing
+10.0.2.15 local-testing local-testing
1.1.1.1 local-testing-ext local-testing-ext.labkey.com
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
::1 localhost ip6-localhost ip6-loopback
-10.0.2.15 local-testing local-testing
- Create hostsfile_entry[127.0.1.1]
Recipe: lk_base::via_hostfile
* hostsfile_entry[1.1.1.1] action create (up to date)
########### Created via the hostfile_entry resource
* hostsfile_entry[2.2.2.2] action create
Recipe: <Dynamically Defined Resource>
* file[/etc/hosts] action create
- update content in file /etc/hosts from 6994f8 to 4c6862
--- /etc/hosts 2017-04-13 00:17:10.693658000 +0000
+++ /etc/.chef-hosts20170413-20240-1bc2sgu 2017-04-13 00:17:10.701662000 +0000
@@ -10,6 +10,7 @@
127.0.0.1 test-node localhost
127.0.1.1 local-testing.test.test local-testing
10.0.2.15 local-testing local-testing
+2.2.2.2 local-testing local-testing-int local-testing.labkey.com local-testing-int.labkey.com
1.1.1.1 local-testing-ext local-testing-ext.labkey.com
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
- Create hostsfile_entry[2.2.2.2]
Recipe: lk_base::via_hostfile
####### Now the hostname resource removes it
* hostname[local-testing] action set
* ohai[reload hostname] action nothing (skipped due to action :nothing)
* execute[set hostname to local-testing] action run (skipped due to not_if)
* file[/etc/hosts] action create
- update content in file /etc/hosts from 4c6862 to 7e4391
--- /etc/hosts 2017-04-13 00:17:10.701662000 +0000
+++ /etc/.chef-hosts20170413-20240-1la4ypz 2017-04-13 00:17:10.737679999 +0000
@@ -9,10 +9,9 @@
127.0.0.1 test-node localhost
127.0.1.1 local-testing.test.test local-testing
-10.0.2.15 local-testing local-testing
-2.2.2.2 local-testing local-testing-int local-testing.labkey.com local-testing-int.labkey.com
1.1.1.1 local-testing-ext local-testing-ext.labkey.com
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
::1 localhost ip6-localhost ip6-loopback
##### Now it adds one of them back in
+10.0.2.15 local-testing local-testing
* execute[hostnamectl set-hostname local-testing] action run (skipped due to not_if)
* ohai[reload hostname] action reload
- re-run ohai and merge results into node attributes
# was: 127.0.1.1 <%= @node[:ec2][:local_hostname] =%> <%= @local_hostname =%> <%= @app_url_hostname =%>
hostsfile_entry '127.0.1.1' do
hostname node['ec2']['local_hostname']
aliases [
node['ec2']['local_hostname'].split('.')[0],
node['lk_base']['customer_url_hostname'],
]
# unique true # needs discussion
action :create
not_if { node['lk_base']['set_hostname'] == 'not_set' }
end
# #############
# # was: <%= @extIP =%> <%= @extString =%>
# ## This may be duplicate of what hostname cookbook does.
hostsfile_entry node['ec2']['public_ipv4'] do
hostname "#{node['lk_base']['set_hostname']}-ext"
aliases [node['lk_base']['set_fqdn_ext']]
action :create
not_if { node['lk_base']['set_hostname'] == 'not_set' }
end
# # was: <%= @intIP =%> <%= @intString =%> <%= @app_url_hostname =%>
hostsfile_entry node['ec2']['local_ipv4'] do
hostname node['lk_base']['set_hostname']
aliases [
"#{node['lk_base']['set_hostname']}-int",
node['lk_base']['set_fqdn'],
node['lk_base']['set_fqdn_int'],
node['lk_base']['customer_url_hostname'],
]
not_if { node['lk_base']['set_hostname'] == 'not_set' }
end
########## This is the resource that fucks things up
# # Update the /etc/hostname file, if required.
hostname "updating hostname to #{node['lk_base']['set_hostname']}" do
hostname node['lk_base']['set_hostname']
only_if { node['lk_base']['set_hostname'] != 'not_set' }
# ipaddress nil
end
@vinyar
Copy link
Author

vinyar commented Apr 13, 2017

setting property ipaddress nil produces the following output:

    hostname "updating hostname to #{node['lk_base']['set_hostname']}" do
      hostname node['lk_base']['set_hostname']
      only_if { node['lk_base']['set_hostname'] != 'not_set' }
      ipaddress nil
    end
   Recipe: lk_base::via_hostfile
     * hostname[updating hostname to local-testing] action set
       * ohai[reload hostname] action nothing (skipped due to action :nothing)
       * execute[set hostname to local-testing] action run (skipped due to not_if)
       * file[/etc/hosts] action create
         - update content in file /etc/hosts from 4c6862 to 7e4391
         --- /etc/hosts	2017-04-13 00:35:22.497261585 +0000
         +++ /etc/.chef-hosts20170413-1753-m5mf6n	2017-04-13 00:35:22.533279583 +0000
         @@ -9,10 +9,9 @@

   127.0.0.1	test-node localhost
   127.0.1.1	local-testing.test.test local-testing
         -10.0.2.15	local-testing local-testing
         -2.2.2.2	local-testing local-testing-int local-testing.labkey.com local-testing-int.labkey.com
   1.1.1.1	local-testing-ext local-testing-ext.labkey.com
   ff02::1	ip6-allnodes
   ff02::2	ip6-allrouters
   ::1	localhost ip6-localhost ip6-loopback
         +10.0.2.15 local-testing local-testing
       * execute[hostnamectl set-hostname local-testing] action run (skipped due to not_if)
       * ohai[reload hostname] action reload
         - re-run ohai and merge results into node attributes

@vinyar
Copy link
Author

vinyar commented Apr 13, 2017

Finally, I just noticed there is another issue:
having this resource definition throws a chef13 warning

#     # Update the /etc/hostname file, if required.
    # hostname "updating hostname to #{node['lk_base']['set_hostname']}" do
    #   hostname node['lk_base']['set_hostname']
    #   only_if { node['lk_base']['set_hostname'] != 'not_set' }
    #   ipaddress nil
    # end
       Deprecated features used!
         An attempt was made to change ipaddress from "10.0.2.15" to nil by calling ipaddress(nil). In Chef 12, this does a get rather than a set. In Chef 13, this will change to set the value to nil. at 1 location:
           - /tmp/kitchen/cache/cookbooks/lk_base/recipes/via_hostfile.rb:131:in `block in from_file'
          See https://docs.chef.io/deprecations_custom_resource_cleanups.html for further details.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment