Skip to content

Commit

Permalink
Fix mixed type comparison resulting in wrong changed (ansible#2772)
Browse files Browse the repository at this point in the history
When using `use_max` or `use_min` in `pam_limits`, the new value is an integer compared with the actual_value which is a string, so they are always different and the module reports a changed but none occurred.
  • Loading branch information
zigarn authored and mattclay committed Dec 8, 2016
1 parent 839adc2 commit f06e2e7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/ansible/modules/extras/system/pam_limits.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,15 +194,15 @@ def main():

if use_max:
if value.isdigit() and actual_value.isdigit():
new_value = max(int(value), int(actual_value))
new_value = str(max(int(value), int(actual_value)))
elif actual_value_unlimited:
new_value = actual_value
else:
new_value = value

if use_min:
if value.isdigit() and actual_value.isdigit():
new_value = min(int(value), int(actual_value))
new_value = str(min(int(value), int(actual_value)))
elif value_unlimited:
new_value = actual_value
else:
Expand All @@ -211,7 +211,7 @@ def main():
# Change line only if value has changed
if new_value != actual_value:
changed = True
new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + str(new_value) + "\n"
new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + new_value + new_comment + "\n"
message = new_limit
nf.write(new_limit)
else:
Expand All @@ -222,7 +222,7 @@ def main():

if not found:
changed = True
new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + str(new_value) + "\n"
new_limit = domain + "\t" + limit_type + "\t" + limit_item + "\t" + new_value + new_comment + "\n"
message = new_limit
nf.write(new_limit)

Expand Down

0 comments on commit f06e2e7

Please sign in to comment.