Skip to content

Commit

Permalink
fix custom file attributes for public keys
Browse files Browse the repository at this point in the history
Use of the confusingly-named _permissions_changed() on both
sides of an `or` was resulting in the second invocation not
being reached if the first invocation returned True, which it
does any time it applied custom attributes to the private key.
As a result, custom file attributes were only ever being
applied to the private key (except in one specific case)

This is fixed by explicitly updating attributes of both files
before checking if changes have been made.

Signed-off-by: Charlie Wheeler-Robinson <[email protected]>
  • Loading branch information
crwr45 committed Jul 20, 2021
1 parent 4908f1a commit 7b60859
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
4 changes: 3 additions & 1 deletion plugins/module_utils/openssh/backends/keypair_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def generate(self):
self.module.fail_json(msg='Unable to update the comment for the public key.')
self._update_comment()

if self._permissions_changed() or self._permissions_changed(public_key=True):
private_key_perms_changed = self._permissions_changed()
public_key_perms_changed = self._permissions_changed(public_key=True)
if private_key_perms_changed or public_key_perms_changed:
self.changed = True

def is_private_key_valid(self, perms_required=True):
Expand Down
1 change: 1 addition & 0 deletions plugins/modules/openssh_keypair.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
- In case the ssh key is broken or password protected, the module will fail.
Set the I(force) option to C(yes) if you want to regenerate the keypair.
- Supports C(check_mode).
- In the case a custom C(mode), C(group), C(owner), or other file attribute is provided it will be applied to both key files.
extends_documentation_fragment: files
'''
Expand Down

0 comments on commit 7b60859

Please sign in to comment.