Skip to content

Commit

Permalink
Add ssh key options parameter to authorized_key module
Browse files Browse the repository at this point in the history
  • Loading branch information
davidminor authored and jimi-c committed Oct 11, 2013
1 parent 41aaad6 commit ed7d3f9
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions library/system/authorized_key
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,16 @@ options:
version_added: "1.2"
state:
description:
- Whether the given key should or should not be in the file
- Whether the given key (with the given key_options) should or should not be in the file
required: false
choices: [ "present", "absent" ]
default: "present"
key_options:
description:
- A string of ssh key options to be prepended to the key in the authorized_keys file
required: false
default: null
version_added: "1.3"
description:
- "Adds or removes authorized keys for particular user accounts"
author: Brad Olson
Expand All @@ -81,6 +87,11 @@ EXAMPLES = '''
with_file:
- public_keys/doe-jane
- public_keys/doe-john
# Using key_options:
- authorized_key: user=charlie
key="{{ lookup('file', '/home/charlie/.ssh/id_rsa.pub') }}"
key_options='no-port-forwarding,host="10.0.1.1"'
'''

# Makes sure the public key line is present or absent in the user's .ssh/authorized_keys.
Expand Down Expand Up @@ -189,6 +200,7 @@ def enforce_state(module, params):
path = params.get("path", None)
manage_dir = params.get("manage_dir", True)
state = params.get("state", "present")
key_options = params.get("key_options", None)

key = key.split('\n')

Expand All @@ -199,6 +211,9 @@ def enforce_state(module, params):

# Check our new keys, if any of them exist we'll continue.
for new_key in key:
if key_options is not None:
new_key = key_options + ' ' + new_key

present = new_key in keys
# handle idempotent state=present
if state=="present":
Expand Down Expand Up @@ -227,7 +242,8 @@ def main():
key = dict(required=True, type='str'),
path = dict(required=False, type='str'),
manage_dir = dict(required=False, type='bool', default=True),
state = dict(default='present', choices=['absent','present'])
state = dict(default='present', choices=['absent','present']),
key_options = dict(required=False, type='str')
)
)

Expand Down

0 comments on commit ed7d3f9

Please sign in to comment.