mirror of
https://github.com/ansible/awx.git
synced 2026-05-07 09:27:36 -02:30
fix a bug in isolated OpenSSH key syncing
OpenSSH keys _must_ end with a \n to be accepted by ssh-add; enforce a newline if there isn't one
This commit is contained in:
@@ -4,6 +4,12 @@ import stat
|
|||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# the purpose of this plugin is to call mkfifo and
|
||||||
|
# write raw SSH key data into the fifo created on the remote isolated host
|
||||||
|
#
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec={
|
argument_spec={
|
||||||
@@ -16,7 +22,14 @@ def main():
|
|||||||
path = module.params['path']
|
path = module.params['path']
|
||||||
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
os.chmod(path, stat.S_IRUSR | stat.S_IWUSR)
|
||||||
with open(path, 'w') as fifo:
|
with open(path, 'w') as fifo:
|
||||||
fifo.write(module.params['content'])
|
data = module.params['content']
|
||||||
|
if 'OPENSSH PRIVATE KEY' in data and not data.endswith('\n'):
|
||||||
|
# we use ansible's lookup() to read this file from the disk,
|
||||||
|
# but ansible's lookup() *strips* newlines
|
||||||
|
# OpenSSH wants certain private keys to end with a newline (or it
|
||||||
|
# won't accept them)
|
||||||
|
data += '\n'
|
||||||
|
fifo.write(data)
|
||||||
module.exit_json(dest=path, changed=True)
|
module.exit_json(dest=path, changed=True)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user