mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix authorized_key module crashing when given an invalid key
I tried a playbook with the following (accidentally wrong) task: tasks: - name: authorized key test authorized_key: key=/home/sam/.ssh/id_rsa.pub key_options='command="/foo/bar"' user=sam I got the following traceback: TASK: [authorized key test] *************************************************** failed: [localhost] => {"failed": true, "parsed": false} Traceback (most recent call last): File "/home/sam/.ansible/tmp/ansible-tmp-1427110003.65-277897441194582/authorized_key", line 2515, in <module> main() File "/home/sam/.ansible/tmp/ansible-tmp-1427110003.65-277897441194582/authorized_key", line 460, in main results = enforce_state(module, module.params) File "/home/sam/.ansible/tmp/ansible-tmp-1427110003.65-277897441194582/authorized_key", line 385, in enforce_state parsed_new_key = (parsed_new_key[0], parsed_new_key[1], parsed_options, parsed_new_key[3]) TypeError: 'NoneType' object has no attribute '__getitem__' With this fix, I see the expected error instead: TASK: [authorized key test] *************************************************** failed: [localhost] => {"failed": true} msg: invalid key specified: /home/sam/.ssh/id_rsa.pub
This commit is contained in:
parent
c04c84887e
commit
5d2652f31b
1 changed files with 4 additions and 3 deletions
|
@ -377,13 +377,14 @@ def enforce_state(module, params):
|
||||||
# Check our new keys, if any of them exist we'll continue.
|
# Check our new keys, if any of them exist we'll continue.
|
||||||
for new_key in key:
|
for new_key in key:
|
||||||
parsed_new_key = parsekey(module, new_key)
|
parsed_new_key = parsekey(module, new_key)
|
||||||
if key_options is not None:
|
|
||||||
parsed_options = parseoptions(module, key_options)
|
|
||||||
parsed_new_key = (parsed_new_key[0], parsed_new_key[1], parsed_options, parsed_new_key[3])
|
|
||||||
|
|
||||||
if not parsed_new_key:
|
if not parsed_new_key:
|
||||||
module.fail_json(msg="invalid key specified: %s" % new_key)
|
module.fail_json(msg="invalid key specified: %s" % new_key)
|
||||||
|
|
||||||
|
if key_options is not None:
|
||||||
|
parsed_options = parseoptions(module, key_options)
|
||||||
|
parsed_new_key = (parsed_new_key[0], parsed_new_key[1], parsed_options, parsed_new_key[3])
|
||||||
|
|
||||||
present = False
|
present = False
|
||||||
matched = False
|
matched = False
|
||||||
non_matching_keys = []
|
non_matching_keys = []
|
||||||
|
|
Loading…
Reference in a new issue