moved 'path exists' function to shell

now it will work with powershell/winrm
This commit is contained in:
Brian Coca 2016-03-25 08:13:44 -07:00
commit 28d20dbe53
4 changed files with 29 additions and 8 deletions

View file

@ -94,6 +94,10 @@ class ShellBase(object):
cmd += '-r '
return cmd + "%s %s" % (path, self._SHELL_REDIRECT_ALLNULL)
def exists(self, path):
cmd = ['test', '-e', pipes.quote(path)]
return ' '.join(cmd)
def mkdtemp(self, basefile=None, system=False, mode=None):
if not basefile:
basefile = 'ansible-tmp-%s-%s' % (time.time(), random.randint(0, 2**48))

View file

@ -94,6 +94,22 @@ class ShellModule(object):
script = 'Write-Host "%s"' % self._escape(user_home_path)
return self._encode_script(script)
def exists(self, path):
path = self._escape(self._unquote(path))
script = '''
If (Test-Path "%s")
{
$res = 0;
}
Else
{
$res = 1;
}
Write-Host "$res";
Exit $res;
''' % path
return self._encode_script(script)
def checksum(self, path, *args, **kwargs):
path = self._escape(self._unquote(path))
script = '''