mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-08-22 22:11:44 -07:00
moved 'path exists' function to shell
now it will work with powershell/winrm
This commit is contained in:
parent
81d9066ee1
commit
28d20dbe53
4 changed files with 29 additions and 8 deletions
|
@ -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))
|
||||
|
|
|
@ -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 = '''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue