AC-632 Fix escaping for ansible-playbook command line when also using ssh-agent.

This commit is contained in:
Chris Church
2013-11-16 16:15:35 -05:00
parent 17899eed3a
commit 40b0608586
2 changed files with 26 additions and 10 deletions

View File

@@ -9,6 +9,7 @@ import distutils.version
import json
import logging
import os
import pipes
import re
import subprocess
import stat
@@ -128,6 +129,9 @@ class BaseTask(Task):
env[k] = '*'*len(str(v))
return env
def args2cmdline(self, *args):
return ' '.join([pipes.quote(a) for a in args])
def build_args(self, instance, **kwargs):
raise NotImplementedError
@@ -378,8 +382,8 @@ class RunJob(BaseTask):
args.append(job.playbook) # relative path to project.local_path
ssh_key_path = kwargs.get('private_data_file', '')
if ssh_key_path:
cmd = ' '.join([subprocess.list2cmdline(['ssh-add', ssh_key_path]),
'&&', subprocess.list2cmdline(args)])
cmd = ' '.join([self.args2cmdline('ssh-add', ssh_key_path),
'&&', self.args2cmdline(*args)])
args = ['ssh-agent', 'sh', '-c', cmd]
return args
@@ -612,7 +616,7 @@ class RunProjectUpdate(BaseTask):
ssh_key_path = kwargs.get('private_data_file', '')
if ssh_key_path:
subcmds = [('ssh-add', ssh_key_path), args]
cmd = ' && '.join([subprocess.list2cmdline(x) for x in subcmds])
cmd = ' && '.join([self.args2cmdline(*x) for x in subcmds])
args = ['ssh-agent', 'sh', '-c', cmd]
return args