Fix missing import and boilerplate
Added fix for missing imports and boilerplate in files modules, also, removed get_exception calls to match 2.6> exception handling. Signed-off-by: Abhijeet Kasurde <akasurde@redhat.com>
This commit is contained in:
parent
11da85f938
commit
bf54a0c3e5
19 changed files with 168 additions and 383 deletions
|
@ -1,19 +1,10 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# This file is part of Ansible
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
from __future__ import absolute_import, division, print_function
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
__metaclass__ = type
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2016, Ben Doherty <bendohmv@gmail.com>
|
# Copyright: (c) 2016, Ben Doherty <bendohmv@gmail.com>
|
||||||
# Sponsored by Oomph, Inc. http://www.oomphinc.com
|
# Sponsored by Oomph, Inc. http://www.oomphinc.com
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -149,8 +139,9 @@ import bz2
|
||||||
import filecmp
|
import filecmp
|
||||||
import zipfile
|
import zipfile
|
||||||
import tarfile
|
import tarfile
|
||||||
|
from traceback import format_exc
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -318,9 +309,8 @@ def main():
|
||||||
else:
|
else:
|
||||||
arcfile.add(fullpath, arcname, recursive=False)
|
arcfile.add(fullpath, arcname, recursive=False)
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
errors.append('%s: %s' % (fullpath, to_native(e)))
|
||||||
errors.append('%s: %s' % (fullpath, str(e)))
|
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
fullpath = dirpath + filename
|
fullpath = dirpath + filename
|
||||||
|
@ -334,9 +324,8 @@ def main():
|
||||||
arcfile.add(fullpath, arcname, recursive=False)
|
arcfile.add(fullpath, arcname, recursive=False)
|
||||||
|
|
||||||
successes.append(fullpath)
|
successes.append(fullpath)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
errors.append('Adding %s: %s' % (path, to_native(e)))
|
||||||
errors.append('Adding %s: %s' % (path, str(e)))
|
|
||||||
else:
|
else:
|
||||||
if format == 'zip':
|
if format == 'zip':
|
||||||
arcfile.write(path, match_root.sub('', path))
|
arcfile.write(path, match_root.sub('', path))
|
||||||
|
@ -345,9 +334,9 @@ def main():
|
||||||
|
|
||||||
successes.append(path)
|
successes.append(path)
|
||||||
|
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg='Error when writing %s archive at %s: %s' % (format == 'zip' and 'zip' or ('tar.' + format), dest, to_native(e)),
|
||||||
return module.fail_json(msg='Error when writing %s archive at %s: %s' % (format == 'zip' and 'zip' or ('tar.' + format), dest, str(e)))
|
exception=format_exc())
|
||||||
|
|
||||||
if arcfile:
|
if arcfile:
|
||||||
arcfile.close()
|
arcfile.close()
|
||||||
|
@ -363,8 +352,7 @@ def main():
|
||||||
shutil.rmtree(path)
|
shutil.rmtree(path)
|
||||||
elif not check_mode:
|
elif not check_mode:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
errors.append(path)
|
errors.append(path)
|
||||||
|
|
||||||
if len(errors) > 0:
|
if len(errors) > 0:
|
||||||
|
@ -421,9 +409,8 @@ def main():
|
||||||
|
|
||||||
successes.append(path)
|
successes.append(path)
|
||||||
|
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
module.fail_json(path=path, dest=dest, msg='Unable to write to compressed file: %s' % to_native(e), exception=format_exc())
|
||||||
module.fail_json(path=path, dest=dest, msg='Unable to write to compressed file: %s' % str(e))
|
|
||||||
|
|
||||||
if arcfile:
|
if arcfile:
|
||||||
arcfile.close()
|
arcfile.close()
|
||||||
|
@ -442,9 +429,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
|
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
module.fail_json(path=path, msg='Unable to remove source file: %s' % to_native(e), exception=format_exc())
|
||||||
module.fail_json(path=path, msg='Unable to remove source file: %s' % str(e))
|
|
||||||
|
|
||||||
params['path'] = dest
|
params['path'] = dest
|
||||||
file_args = module.load_file_common_arguments(params)
|
file_args = module.load_file_common_arguments(params)
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Stephen Fromm <sfromm@gmail.com>
|
# Copyright: (c) 2012, Stephen Fromm <sfromm@gmail.com>
|
||||||
# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
|
# Copyright: (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -125,8 +115,8 @@ import re
|
||||||
import tempfile
|
import tempfile
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils.six import b
|
from ansible.module_utils.six import b
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
# ===========================================
|
# ===========================================
|
||||||
|
@ -178,11 +168,10 @@ def cleanup(path, result=None):
|
||||||
if os.path.exists(path):
|
if os.path.exists(path):
|
||||||
try:
|
try:
|
||||||
os.remove(path)
|
os.remove(path)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError) as e:
|
||||||
e = get_exception()
|
|
||||||
# don't error on possible race conditions, but keep warning
|
# don't error on possible race conditions, but keep warning
|
||||||
if result is not None:
|
if result is not None:
|
||||||
result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, str(e))]
|
result['warnings'] = ['Unable to remove temp file (%s): %s' % (path, to_native(e))]
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -224,9 +213,8 @@ def main():
|
||||||
if regexp is not None:
|
if regexp is not None:
|
||||||
try:
|
try:
|
||||||
compiled_regexp = re.compile(regexp)
|
compiled_regexp = re.compile(regexp)
|
||||||
except re.error:
|
except re.error as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (to_native(e), regexp))
|
||||||
module.fail_json(msg="Invalid Regexp (%s) in \"%s\"" % (e, regexp))
|
|
||||||
|
|
||||||
if validate and "%s" not in validate:
|
if validate and "%s" not in validate:
|
||||||
module.fail_json(msg="validate must contain %%s: %s" % validate)
|
module.fail_json(msg="validate must contain %%s: %s" % validate)
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2014, 2015 YAEGASHI Takeshi <yaegashi@debian.org>
|
# Copyright: (c) 2014, 2015 YAEGASHI Takeshi <yaegashi@debian.org>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -167,6 +157,7 @@ from ansible.module_utils.six import b
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes
|
||||||
|
|
||||||
|
|
||||||
def write_changes(module, contents, path):
|
def write_changes(module, contents, path):
|
||||||
|
|
||||||
tmpfd, tmpfile = tempfile.mkstemp()
|
tmpfd, tmpfile = tempfile.mkstemp()
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
# Copyright: (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -238,7 +228,6 @@ import traceback
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils._text import to_bytes, to_native
|
from ansible.module_utils._text import to_bytes, to_native
|
||||||
|
|
||||||
|
|
||||||
|
@ -359,8 +348,7 @@ def main():
|
||||||
# the execute bit for the current user set, in
|
# the execute bit for the current user set, in
|
||||||
# which case the stat() call will raise an OSError
|
# which case the stat() call will raise an OSError
|
||||||
os.stat(os.path.dirname(b_dest))
|
os.stat(os.path.dirname(b_dest))
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
if "permission denied" in to_native(e).lower():
|
if "permission denied" in to_native(e).lower():
|
||||||
module.fail_json(msg="Destination directory %s is not accessible" % (os.path.dirname(dest)))
|
module.fail_json(msg="Destination directory %s is not accessible" % (os.path.dirname(dest)))
|
||||||
module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest)))
|
module.fail_json(msg="Destination directory %s does not exist" % (os.path.dirname(dest)))
|
||||||
|
|
|
@ -1,19 +1,6 @@
|
||||||
# this is a virtual module that is entirely implemented server side
|
# this is a virtual module that is entirely implemented server side
|
||||||
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
# Copyright: (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -140,7 +130,6 @@ import time
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils.six import b
|
from ansible.module_utils.six import b
|
||||||
from ansible.module_utils._text import to_bytes, to_native
|
from ansible.module_utils._text import to_bytes, to_native
|
||||||
|
|
||||||
|
@ -285,15 +274,13 @@ def main():
|
||||||
if prev_state == 'directory':
|
if prev_state == 'directory':
|
||||||
try:
|
try:
|
||||||
shutil.rmtree(b_path, ignore_errors=False)
|
shutil.rmtree(b_path, ignore_errors=False)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="rmtree failed: %s" % to_native(e))
|
||||||
module.fail_json(msg="rmtree failed: %s" % str(e))
|
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.unlink(b_path)
|
os.unlink(b_path)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(path=path, msg="unlinking failed: %s " % to_native(e))
|
||||||
module.fail_json(path=path, msg="unlinking failed: %s " % str(e))
|
|
||||||
module.exit_json(path=path, changed=True, diff=diff)
|
module.exit_json(path=path, changed=True, diff=diff)
|
||||||
else:
|
else:
|
||||||
module.exit_json(path=path, changed=False)
|
module.exit_json(path=path, changed=False)
|
||||||
|
@ -341,8 +328,7 @@ def main():
|
||||||
if not os.path.exists(b_curpath):
|
if not os.path.exists(b_curpath):
|
||||||
try:
|
try:
|
||||||
os.mkdir(b_curpath)
|
os.mkdir(b_curpath)
|
||||||
except OSError:
|
except OSError as ex:
|
||||||
ex = get_exception()
|
|
||||||
# Possibly something else created the dir since the os.path.exists
|
# Possibly something else created the dir since the os.path.exists
|
||||||
# check above. As long as it's a dir, we don't need to error out.
|
# check above. As long as it's a dir, we don't need to error out.
|
||||||
if not (ex.errno == errno.EEXIST and os.path.isdir(b_curpath)):
|
if not (ex.errno == errno.EEXIST and os.path.isdir(b_curpath)):
|
||||||
|
@ -350,9 +336,8 @@ def main():
|
||||||
tmp_file_args = file_args.copy()
|
tmp_file_args = file_args.copy()
|
||||||
tmp_file_args['path'] = curpath
|
tmp_file_args['path'] = curpath
|
||||||
changed = module.set_fs_attributes_if_different(tmp_file_args, changed, diff)
|
changed = module.set_fs_attributes_if_different(tmp_file_args, changed, diff)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(path=path, msg='There was an issue creating %s as requested: %s' % (curpath, to_native(e)))
|
||||||
module.fail_json(path=path, msg='There was an issue creating %s as requested: %s' % (curpath, str(e)))
|
|
||||||
|
|
||||||
# We already know prev_state is not 'absent', therefore it exists in some form.
|
# We already know prev_state is not 'absent', therefore it exists in some form.
|
||||||
elif prev_state != 'directory':
|
elif prev_state != 'directory':
|
||||||
|
@ -434,8 +419,7 @@ def main():
|
||||||
else:
|
else:
|
||||||
os.symlink(b_src, b_tmppath)
|
os.symlink(b_src, b_tmppath)
|
||||||
os.rename(b_tmppath, b_path)
|
os.rename(b_tmppath, b_path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
if os.path.exists(b_tmppath):
|
if os.path.exists(b_tmppath):
|
||||||
os.unlink(b_tmppath)
|
os.unlink(b_tmppath)
|
||||||
module.fail_json(path=path, msg='Error while replacing: %s' % to_native(e, nonstring='simplerepr'))
|
module.fail_json(path=path, msg='Error while replacing: %s' % to_native(e, nonstring='simplerepr'))
|
||||||
|
@ -445,8 +429,7 @@ def main():
|
||||||
os.link(b_src, b_path)
|
os.link(b_src, b_path)
|
||||||
else:
|
else:
|
||||||
os.symlink(b_src, b_path)
|
os.symlink(b_src, b_path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
module.fail_json(path=path, msg='Error while linking: %s' % to_native(e, nonstring='simplerepr'))
|
module.fail_json(path=path, msg='Error while linking: %s' % to_native(e, nonstring='simplerepr'))
|
||||||
|
|
||||||
if module.check_mode and not os.path.exists(b_path):
|
if module.check_mode and not os.path.exists(b_path):
|
||||||
|
@ -461,21 +444,18 @@ def main():
|
||||||
if prev_state == 'absent':
|
if prev_state == 'absent':
|
||||||
try:
|
try:
|
||||||
open(b_path, 'wb').close()
|
open(b_path, 'wb').close()
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
module.fail_json(path=path, msg='Error, could not touch target: %s' % to_native(e, nonstring='simplerepr'))
|
module.fail_json(path=path, msg='Error, could not touch target: %s' % to_native(e, nonstring='simplerepr'))
|
||||||
elif prev_state in ('file', 'directory', 'hard'):
|
elif prev_state in ('file', 'directory', 'hard'):
|
||||||
try:
|
try:
|
||||||
os.utime(b_path, None)
|
os.utime(b_path, None)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
module.fail_json(path=path, msg='Error while touching existing target: %s' % to_native(e, nonstring='simplerepr'))
|
module.fail_json(path=path, msg='Error while touching existing target: %s' % to_native(e, nonstring='simplerepr'))
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state))
|
module.fail_json(msg='Cannot touch other than files, directories, and hardlinks (%s is %s)' % (path, prev_state))
|
||||||
try:
|
try:
|
||||||
module.set_fs_attributes_if_different(file_args, True, diff)
|
module.set_fs_attributes_if_different(file_args, True, diff)
|
||||||
except SystemExit:
|
except SystemExit as e:
|
||||||
e = get_exception()
|
|
||||||
if e.code:
|
if e.code:
|
||||||
# We take this to mean that fail_json() was called from
|
# We take this to mean that fail_json() was called from
|
||||||
# somewhere in basic.py
|
# somewhere in basic.py
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2014, Ruggero Marchei <ruggero.marchei@daemonzone.net>
|
# Copyright: (c) 2014, Ruggero Marchei <ruggero.marchei@daemonzone.net>
|
||||||
# (c) 2015, Brian Coca <bcoca@ansible.com>
|
# Copyright: (c) 2015, Brian Coca <bcoca@ansible.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Jan-Piet Mens <jpmens () gmail.com>
|
# Copyright: (c) 2012, Jan-Piet Mens <jpmens () gmail.com>
|
||||||
# (c) 2015, Ales Nosek <anosek.nosek () gmail.com>
|
# Copyright: (c) 2015, Ales Nosek <anosek.nosek () gmail.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
#
|
#
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2013, Jeroen Hoekx <jeroen.hoekx@dsquare.be>
|
# Copyright: (c) 2013, Jeroen Hoekx <jeroen.hoekx@dsquare.be>
|
||||||
# (c) 2016, Matt Robinson <git@nerdoftheherd.com>
|
# Copyright: (c) 2016, Matt Robinson <git@nerdoftheherd.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
|
# Copyright: (c) 2012, Daniel Hokka Zakrisson <daniel@hozac.com>
|
||||||
# (c) 2014, Ahti Kitsik <ak@ahtik.com>
|
# Copyright: (c) 2014, Ahti Kitsik <ak@ahtik.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
|
|
@ -1,23 +1,13 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Luis Alberto Perez Lazaro <luisperlazaro@gmail.com>
|
# Copyright: (c) 2012, Luis Alberto Perez Lazaro <luisperlazaro@gmail.com>
|
||||||
# (c) 2015, Jakub Jirutka <jakub@jirutka.cz>
|
# Copyright: (c) 2015, Jakub Jirutka <jakub@jirutka.cz>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -97,8 +87,9 @@ EXAMPLES = r'''
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
from traceback import format_exc
|
||||||
from ansible.module_utils.basic import AnsibleModule, get_exception
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
|
|
||||||
class PatchError(Exception):
|
class PatchError(Exception):
|
||||||
|
@ -186,9 +177,8 @@ def main():
|
||||||
apply_patch(patch_func, p.src, p.basedir, dest_file=p.dest, binary=p.binary, strip=p.strip,
|
apply_patch(patch_func, p.src, p.basedir, dest_file=p.dest, binary=p.binary, strip=p.strip,
|
||||||
dry_run=module.check_mode, backup=p.backup)
|
dry_run=module.check_mode, backup=p.backup)
|
||||||
changed = True
|
changed = True
|
||||||
except PatchError:
|
except PatchError as e:
|
||||||
e = get_exception()
|
module.fail_json(msg=to_native(e), exception=format_exc())
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
|
|
||||||
module.exit_json(changed=changed)
|
module.exit_json(changed=changed)
|
||||||
|
|
||||||
|
|
|
@ -1,22 +1,12 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2013, Evan Kaufman <evan@digitalflophouse.com
|
# Copyright: (c) 2013, Evan Kaufman <evan@digitalflophouse.com
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# This file is part of Ansible
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
from __future__ import absolute_import, division, print_function
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
__metaclass__ = type
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -372,7 +363,6 @@ import stat
|
||||||
|
|
||||||
# import module snippets
|
# import module snippets
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils._text import to_bytes
|
from ansible.module_utils._text import to_bytes
|
||||||
|
|
||||||
|
|
||||||
|
@ -469,8 +459,7 @@ def main():
|
||||||
st = os.stat(b_path)
|
st = os.stat(b_path)
|
||||||
else:
|
else:
|
||||||
st = os.lstat(b_path)
|
st = os.lstat(b_path)
|
||||||
except OSError:
|
except OSError as e:
|
||||||
e = get_exception()
|
|
||||||
if e.errno == errno.ENOENT:
|
if e.errno == errno.ENOENT:
|
||||||
output = {'exists': False}
|
output = {'exists': False}
|
||||||
module.exit_json(changed=False, stat=output)
|
module.exit_json(changed=False, stat=output)
|
||||||
|
|
|
@ -1,20 +1,11 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
# Copyright: (c) 2012-2013, Timothy Appnel <tim@appnel.com>
|
||||||
|
# Copyright: (c) 2017, Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# (c) 2012-2013, Timothy Appnel <tim@appnel.com>
|
from __future__ import absolute_import, division, print_function
|
||||||
#
|
__metaclass__ = type
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
|
|
@ -1,22 +1,11 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
#coding: utf-8 -*-
|
#coding: utf-8 -*-
|
||||||
|
# Copyright: (c) 2016 Krzysztof Magosa <krzysztof@magosa.pl>
|
||||||
|
# Copyright: (c) 2017, Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# (c) 2016 Krzysztof Magosa <krzysztof@magosa.pl>
|
from __future__ import absolute_import, division, print_function
|
||||||
#
|
__metaclass__ = type
|
||||||
# This file is part of Ansible
|
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -81,10 +70,11 @@ path:
|
||||||
sample: "/tmp/ansible.bMlvdk"
|
sample: "/tmp/ansible.bMlvdk"
|
||||||
'''
|
'''
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from tempfile import mkstemp, mkdtemp
|
|
||||||
from os import close
|
from os import close
|
||||||
|
from tempfile import mkstemp, mkdtemp
|
||||||
|
from traceback import format_exc
|
||||||
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
|
from ansible.module_utils._text import to_native
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
|
@ -112,9 +102,8 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
module.exit_json(changed=True, path=path)
|
module.exit_json(changed=True, path=path)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg=to_native(e), exception=format_exc())
|
||||||
module.fail_json(msg=str(e))
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
|
@ -1,19 +1,9 @@
|
||||||
# this is a virtual module that is entirely implemented server side
|
# this is a virtual module that is entirely implemented server side
|
||||||
|
# Copyright: (c) 2017, Ansible Project
|
||||||
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
|
|
||||||
# This file is part of Ansible
|
from __future__ import absolute_import, division, print_function
|
||||||
#
|
__metaclass__ = type
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
|
|
@ -1,25 +1,15 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
# Copyright: (c) 2012, Michael DeHaan <michael.dehaan@gmail.com>
|
||||||
# (c) 2013, Dylan Martin <dmartin@seattlecentral.edu>
|
# Copyright: (c) 2013, Dylan Martin <dmartin@seattlecentral.edu>
|
||||||
# (c) 2015, Toshio Kuratomi <tkuratomi@ansible.com>
|
# Copyright: (c) 2015, Toshio Kuratomi <tkuratomi@ansible.com>
|
||||||
# (c) 2016, Dag Wieers <dag@wieers.com>
|
# Copyright: (c) 2016, Dag Wieers <dag@wieers.com>
|
||||||
#
|
# Copyright: (c) 2017, Ansible Project
|
||||||
# This file is part of Ansible
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
#
|
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
from __future__ import absolute_import, division, print_function
|
||||||
# it under the terms of the GNU General Public License as published by
|
__metaclass__ = type
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['preview'],
|
'status': ['preview'],
|
||||||
|
@ -142,7 +132,6 @@ import time
|
||||||
from zipfile import ZipFile, BadZipfile
|
from zipfile import ZipFile, BadZipfile
|
||||||
|
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
|
||||||
from ansible.module_utils.urls import fetch_url
|
from ansible.module_utils.urls import fetch_url
|
||||||
from ansible.module_utils._text import to_bytes, to_native, to_text
|
from ansible.module_utils._text import to_bytes, to_native, to_text
|
||||||
|
|
||||||
|
@ -227,8 +216,7 @@ class ZipArchive(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
archive = ZipFile(self.src)
|
archive = ZipFile(self.src)
|
||||||
except BadZipfile:
|
except BadZipfile as e:
|
||||||
e = get_exception()
|
|
||||||
if e.args[0].lower().startswith('bad magic number'):
|
if e.args[0].lower().startswith('bad magic number'):
|
||||||
# Python2.4 can't handle zipfiles with > 64K files. Try using
|
# Python2.4 can't handle zipfiles with > 64K files. Try using
|
||||||
# /usr/bin/unzip instead
|
# /usr/bin/unzip instead
|
||||||
|
@ -253,8 +241,7 @@ class ZipArchive(object):
|
||||||
self._files_in_archive = []
|
self._files_in_archive = []
|
||||||
try:
|
try:
|
||||||
archive = ZipFile(self.src)
|
archive = ZipFile(self.src)
|
||||||
except BadZipfile:
|
except BadZipfile as e:
|
||||||
e = get_exception()
|
|
||||||
if e.args[0].lower().startswith('bad magic number'):
|
if e.args[0].lower().startswith('bad magic number'):
|
||||||
# Python2.4 can't handle zipfiles with > 64K files. Try using
|
# Python2.4 can't handle zipfiles with > 64K files. Try using
|
||||||
# /usr/bin/unzip instead
|
# /usr/bin/unzip instead
|
||||||
|
@ -491,9 +478,8 @@ class ZipArchive(object):
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
mode = int(self.file_args['mode'], 8)
|
mode = int(self.file_args['mode'], 8)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
self.module.fail_json(path=path, msg="mode %(mode)s must be in octal form" % self.file_args, details=to_native(e))
|
||||||
self.module.fail_json(path=path, msg="mode %(mode)s must be in octal form" % self.file_args, details=str(e))
|
|
||||||
# Only special files require no umask-handling
|
# Only special files require no umask-handling
|
||||||
elif ztype == '?':
|
elif ztype == '?':
|
||||||
mode = self._permstr_to_octal(permstr, 0)
|
mode = self._permstr_to_octal(permstr, 0)
|
||||||
|
@ -812,9 +798,8 @@ def main():
|
||||||
f.write(data)
|
f.write(data)
|
||||||
f.close()
|
f.close()
|
||||||
src = package
|
src = package
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Failure downloading %s, %s" % (src, to_native(e)))
|
||||||
module.fail_json(msg="Failure downloading %s, %s" % (src, e))
|
|
||||||
else:
|
else:
|
||||||
module.fail_json(msg="Source '%s' does not exist" % src)
|
module.fail_json(msg="Source '%s' does not exist" % src)
|
||||||
if not os.access(src, os.R_OK):
|
if not os.access(src, os.R_OK):
|
||||||
|
@ -824,9 +809,8 @@ def main():
|
||||||
try:
|
try:
|
||||||
if os.path.getsize(src) == 0:
|
if os.path.getsize(src) == 0:
|
||||||
module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src)
|
module.fail_json(msg="Invalid archive '%s', the file is 0 bytes" % src)
|
||||||
except Exception:
|
except Exception as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Source '%s' not readable, %s" % (src, to_native(e)))
|
||||||
module.fail_json(msg="Source '%s' not readable" % src)
|
|
||||||
|
|
||||||
# is dest OK to receive tar file?
|
# is dest OK to receive tar file?
|
||||||
if not os.path.isdir(dest):
|
if not os.path.isdir(dest):
|
||||||
|
@ -868,9 +852,8 @@ def main():
|
||||||
file_args['path'] = os.path.join(dest, filename)
|
file_args['path'] = os.path.join(dest, filename)
|
||||||
try:
|
try:
|
||||||
res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'], expand=False)
|
res_args['changed'] = module.set_fs_attributes_if_different(file_args, res_args['changed'], expand=False)
|
||||||
except (IOError, OSError):
|
except (IOError, OSError) as e:
|
||||||
e = get_exception()
|
module.fail_json(msg="Unexpected error when accessing exploded file: %s" % to_native(e), **res_args)
|
||||||
module.fail_json(msg="Unexpected error when accessing exploded file: %s" % e, **res_args)
|
|
||||||
|
|
||||||
if module.params['list_files']:
|
if module.params['list_files']:
|
||||||
res_args['files'] = handler.files_in_archive
|
res_args['files'] = handler.files_in_archive
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# This file is part of Ansible
|
# Copyright: (c) 2017, Ansible Project
|
||||||
#
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||||
# Ansible is free software: you can redistribute it and/or modify
|
|
||||||
# it under the terms of the GNU General Public License as published by
|
from __future__ import absolute_import, division, print_function
|
||||||
# the Free Software Foundation, either version 3 of the License, or
|
__metaclass__ = type
|
||||||
# (at your option) any later version.
|
|
||||||
#
|
|
||||||
# Ansible is distributed in the hope that it will be useful,
|
|
||||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
# GNU General Public License for more details.
|
|
||||||
#
|
|
||||||
# You should have received a copy of the GNU General Public License
|
|
||||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
||||||
|
|
||||||
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
ANSIBLE_METADATA = {'metadata_version': '1.0',
|
||||||
'status': ['stableinterface'],
|
'status': ['stableinterface'],
|
||||||
|
@ -95,6 +86,7 @@ import os
|
||||||
from ansible.module_utils.basic import AnsibleModule
|
from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.pycompat24 import get_exception
|
from ansible.module_utils.pycompat24 import get_exception
|
||||||
|
|
||||||
|
|
||||||
def get_xattr_keys(module,path,follow):
|
def get_xattr_keys(module,path,follow):
|
||||||
cmd = [ module.get_bin_path('getfattr', True) ]
|
cmd = [ module.get_bin_path('getfattr', True) ]
|
||||||
# prevents warning and not sure why it's not default
|
# prevents warning and not sure why it's not default
|
||||||
|
|
Loading…
Reference in a new issue