Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update entry without priority set in attributes results to priority 0 #96

Open
WeetA34 opened this issue Nov 27, 2017 · 0 comments
Open

Comments

@WeetA34
Copy link

WeetA34 commented Nov 27, 2017

Hello

i had an issue with priority.
When i use two update actions without specifying the priority in attributes, chef always update my entries.

hostsfile_entry '192.168.1.2' do
        hostname        'server01.weeta.lab'
        aliases         ['server01', 'server01.test.lab']
        comment         'Update by Chef'
        action          :update
end

hostsfile_entry '192.168.1.3' do
        hostname        'server02.weeta.lab'
        aliases         ['server02', 'server02.test.lab']
        comment         'Update by Chef'
        action          :update
end

After some investigations, i found when priority is not defined in attributes, options[:priority] is nil. Calculated priority of an ipv4 ip (60) is replaced by 0 due to -e.priority.to_i in manipulator unique_entries method. So the updated entry is always moved to the end.
When you only have one entry in your recipe, it's OK but when you have 2 or more entries without static priority, the first one is moved to the end then the second one is moved to the end. It happens each time the chef client is executed.

I resolved my issue by modifying the code like this:

--- entry.rb.orig       2017-08-23 02:34:23.000000000 +0200
+++ entry.rb    2017-11-27 18:51:18.854049200 +0100
@@ -127,8 +127,12 @@
     # @param [Integer] new_priority
     #   the new priority to set
     def priority=(new_priority)
-      @calculated_priority = false
-      @priority = new_priority
+      if new_priority.nil?
+        @priority = calculated_priority
+      else
+        @calculated_priority = false
+        @priority = new_priority
+      end
     end

     # The line representation of this entry.

Rgds
Stéphane Olivier

@WeetA34 WeetA34 changed the title update entry without priority in options result to priority 0 update entry without priority set in attributes results to priority 0 Nov 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant