diff --git a/docsite/rst/faq.rst b/docsite/rst/faq.rst index 1b499c5474..ba3ae1264f 100644 --- a/docsite/rst/faq.rst +++ b/docsite/rst/faq.rst @@ -3,15 +3,17 @@ Frequently Asked Questions Here are some commonly-asked questions and their answers. -.. _users_and_ports: +.. _set_environment: -If you are looking to set environment variables remotely for your project (in a task, not locally for Ansible) -The keyword is simply `environment` +How can I set the PATH or any other environment variable for a task or entire playbook? ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + +Setting environment variables can be done with the `environment` keyword. It can be used at task or playbook level:: + + environment: + PATH: {{ ansible_env.PATH }}:/thingy/bin + SOME: value -``` - environment: - PATH:$PATH:/thingy/bin -``` How do I handle different machines needing different user accounts or ports to log in with? diff --git a/docsite/rst/intro.rst b/docsite/rst/intro.rst index 9b30a18bbb..7976462383 100644 --- a/docsite/rst/intro.rst +++ b/docsite/rst/intro.rst @@ -1,7 +1,7 @@ Introduction ============ -Before we dive into the really fun parts -- playbooks, configuration management, deployment, and orchestration, we'll learn how to get Ansible installed and some basic concepts. We'll go over how to execute ad-hoc commands in parallel across your nodes using /usr/bin/ansible. We'll also see what sort of modules are available in Ansible's core (though you can also write your own, which we'll also show later). +Before we dive into the really fun parts -- playbooks, configuration management, deployment, and orchestration, we'll learn how to get Ansible installed and cover some basic concepts. We'll also go over how to execute ad-hoc commands in parallel across your nodes using /usr/bin/ansible. Additionally, we'll see what sort of modules are available in Ansible's core (though you can also write your own, which is also covered later). .. toctree:: :maxdepth: 1 diff --git a/docsite/rst/intro_getting_started.rst b/docsite/rst/intro_getting_started.rst index 6713603647..c1cd5571e6 100644 --- a/docsite/rst/intro_getting_started.rst +++ b/docsite/rst/intro_getting_started.rst @@ -11,10 +11,10 @@ Foreword Now that you've read :doc:`intro_installation` and installed Ansible, it's time to dig in and get started with some commands. -What we are showing first are not the powerful configuration/deployment/orchestration of Ansible, called playbooks. -Playbooks are covered in a separate section. +What we are showing first are not the powerful configuration/deployment/orchestration features of Ansible. +These features are handled by playbooks which are covered in a separate section. -This section is about how to get going initially. Once you have these concepts down, read :doc:`intro_adhoc` for some more +This section is about how to initially get going. Once you have these concepts down, read :doc:`intro_adhoc` for some more detail, and then you'll be ready to dive into playbooks and explore the most interesting parts! .. _remote_connection_information: @@ -22,21 +22,20 @@ detail, and then you'll be ready to dive into playbooks and explore the most int Remote Connection Information ````````````````````````````` -Before we get started, it's important to understand how Ansible is communicating with remote +Before we get started, it's important to understand how Ansible communicates with remote machines over SSH. By default, Ansible 1.3 and later will try to use native -OpenSSH for remote communication when possible. This enables both ControlPersist (a performance feature), Kerberos, and options in ~/.ssh/config such as Jump Host setup. When using Enterprise Linux 6 operating systems as the control machine (Red Hat Enterprise Linux and derivatives such as CentOS), however, the version of OpenSSH may be too old to support ControlPersist. On these operating systems, Ansible will fallback into using a high-quality Python implementation of +OpenSSH for remote communication when possible. This enables ControlPersist (a performance feature), Kerberos, and options in ~/.ssh/config such as Jump Host setup. However, when using Enterprise Linux 6 operating systems as the control machine (Red Hat Enterprise Linux and derivatives such as CentOS), the version of OpenSSH may be too old to support ControlPersist. On these operating systems, Ansible will fallback into using a high-quality Python implementation of OpenSSH called 'paramiko'. If you wish to use features like Kerberized SSH and more, consider using Fedora, OS X, or Ubuntu as your control machine until a newer version of OpenSSH is available for your platform -- or engage 'accelerated mode' in Ansible. See :doc:`playbooks_acceleration`. -In Ansible 1.2 and before, the default was strictly paramiko and native SSH had to be explicitly selected with -c ssh or set in the configuration file. +In releases up to and including Ansible 1.2, the default was strictly paramiko. Native SSH had to be explicitly selected with the -c ssh option or set in the configuration file. -Occasionally you'll encounter a device that doesn't do SFTP. This is rare, but if talking with some remote devices that don't support SFTP, you can switch to SCP mode in :doc:`intro_configuration`. +Occasionally you'll encounter a device that doesn't support SFTP. This is rare, but should it occur, you can switch to SCP mode in :doc:`intro_configuration`. -When speaking with remote machines, Ansible will by default assume you are using SSH keys -- which we encourage -- but passwords are fine too. To enable password auth, supply the option ``--ask-pass`` where needed. If using sudo features and when sudo requires a password, also supply ``--ask-sudo-pass`` as appropriate. +When speaking with remote machines, Ansible by default assumes you are using SSH keys. SSH keys are encouraged but password authentication can also be used where needed by supplying the option ``--ask-pass``. If using sudo features and when sudo requires a password, also supply ``--ask-sudo-pass``. -While it may be common sense, it is worth sharing: Any management system benefits from being run near the machines being managed. If running in a cloud, consider running Ansible from a machine inside that cloud. It will work better than on the open -internet in most cases. +While it may be common sense, it is worth sharing: Any management system benefits from being run near the machines being managed. If you are running Ansible in a cloud, consider running it from a machine inside that cloud. In most cases this will work better than on the open Internet. As an advanced topic, Ansible doesn't just have to connect remotely over SSH. The transports are pluggable, and there are options for managing things locally, as well as managing chroot, lxc, and jail containers. A mode called 'ansible-pull' can also invert the system and have systems 'phone home' via scheduled git checkouts to pull configuration directives from a central repository. @@ -47,8 +46,8 @@ Your first commands Now that you've installed Ansible, it's time to get started with some basics. -Edit (or create) /etc/ansible/hosts and put one or more remote systems in it, for -which you have your SSH key in ``authorized_keys``:: +Edit (or create) /etc/ansible/hosts and put one or more remote systems in it. Your +public SSH key should be located in ``authorized_keys`` on those systems:: 192.168.1.50 aserver.example.org @@ -95,9 +94,9 @@ Now run a live command on all of your nodes: $ ansible all -a "/bin/echo hello" -Congratulations. You've just contacted your nodes with Ansible. It's -soon going to be time to read some of the more real-world :doc:`intro_adhoc`, and explore -what you can do with different modules, as well as the Ansible +Congratulations! You've just contacted your nodes with Ansible. It's +soon going to be time to: read about some more real-world cases in :doc:`intro_adhoc`, +explore what you can do with different modules, and to learn about the Ansible :doc:`playbooks` language. Ansible is not just about running commands, it also has powerful configuration management and deployment features. There's more to explore, but you already have a fully working infrastructure! @@ -111,7 +110,7 @@ Ansible 1.2.1 and later have host key checking enabled by default. If a host is reinstalled and has a different key in 'known_hosts', this will result in an error message until corrected. If a host is not initially in 'known_hosts' this will result in prompting for confirmation of the key, which results in an interactive experience if using Ansible, from say, cron. You might not want this. -If you wish to disable this behavior and understand the implications, you can do so by editing /etc/ansible/ansible.cfg or ~/.ansible.cfg:: +If you understand the implications and wish to disable this behavior, you can do so by editing /etc/ansible/ansible.cfg or ~/.ansible.cfg:: [defaults] host_key_checking = False @@ -126,7 +125,7 @@ Also note that host key checking in paramiko mode is reasonably slow, therefore .. _a_note_about_logging: -Ansible will log some information about module arguments on the remote system in the remote syslog, unless a task or play is marked with a "no_log: True" attribute, explained later. +Ansible will log some information about module arguments on the remote system in the remote syslog, unless a task or play is marked with a "no_log: True" attribute. This is explained later. To enable basic logging on the control machine see :doc:`intro_configuration` document and set the 'log_path' configuration file setting. Enterprise users may also be interested in :doc:`tower`. Tower provides a very robust database logging feature where it is possible to drill down and see history based on hosts, projects, and particular inventories over time -- explorable both graphically and through a REST API. diff --git a/docsite/rst/playbooks_conditionals.rst b/docsite/rst/playbooks_conditionals.rst index 2474998226..bdadaf5971 100644 --- a/docsite/rst/playbooks_conditionals.rst +++ b/docsite/rst/playbooks_conditionals.rst @@ -28,6 +28,14 @@ It's actually pretty simple:: command: /sbin/shutdown -t now when: ansible_os_family == "Debian" +You can also use parentheses to group conditions:: + + tasks: + - name: "shutdown CentOS 6 and 7 systems" + command: /sbin/shutdown -t now + when: ansible_distribution == "CentOS" and + (ansible_distribution_major_version == "6" or ansible_distribution_major_version == "7") + A number of Jinja2 "filters" can also be used in when statements, some of which are unique and provided by Ansible. Suppose we want to ignore the error of one statement and then decide to do something conditionally based on success or failure:: diff --git a/v2/ansible/executor/module_common.py b/v2/ansible/executor/module_common.py index 23890d64e6..535fbd45e3 100644 --- a/v2/ansible/executor/module_common.py +++ b/v2/ansible/executor/module_common.py @@ -21,7 +21,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type # from python and deps -from cStringIO import StringIO +from six.moves import StringIO import json import os import shlex diff --git a/v2/ansible/executor/playbook_executor.py b/v2/ansible/executor/playbook_executor.py index 8af19ed378..6f0bf31f33 100644 --- a/v2/ansible/executor/playbook_executor.py +++ b/v2/ansible/executor/playbook_executor.py @@ -16,7 +16,7 @@ # along with Ansible. If not, see . # Make coding more python3-ish -from __future__ import (absolute_import, division) +from __future__ import (absolute_import, division, print_function) __metaclass__ = type import signal diff --git a/v2/ansible/inventory/__init__.py b/v2/ansible/inventory/__init__.py index c8e3cddeba..063398f17f 100644 --- a/v2/ansible/inventory/__init__.py +++ b/v2/ansible/inventory/__init__.py @@ -16,6 +16,9 @@ # along with Ansible. If not, see . ############################################# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import fnmatch import os import sys diff --git a/v2/ansible/inventory/dir.py b/v2/ansible/inventory/dir.py index 52f7af8b53..73c882f288 100644 --- a/v2/ansible/inventory/dir.py +++ b/v2/ansible/inventory/dir.py @@ -17,6 +17,8 @@ # along with Ansible. If not, see . ############################################# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/inventory/expand_hosts.py b/v2/ansible/inventory/expand_hosts.py index f129740935..b5a957c53f 100644 --- a/v2/ansible/inventory/expand_hosts.py +++ b/v2/ansible/inventory/expand_hosts.py @@ -30,6 +30,9 @@ expanded into 001, 002 ...009, 010. Note that when beg is specified with left zero padding, then the length of end must be the same as that of beg, else an exception is raised. ''' +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import string from ansible import errors diff --git a/v2/ansible/inventory/group.py b/v2/ansible/inventory/group.py index 87d6f64dfc..6525e69b46 100644 --- a/v2/ansible/inventory/group.py +++ b/v2/ansible/inventory/group.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.utils.debug import debug diff --git a/v2/ansible/inventory/ini.py b/v2/ansible/inventory/ini.py index 4236140ac8..e004ee8bb7 100644 --- a/v2/ansible/inventory/ini.py +++ b/v2/ansible/inventory/ini.py @@ -16,6 +16,8 @@ # along with Ansible. If not, see . ############################################# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import ast import shlex diff --git a/v2/ansible/inventory/script.py b/v2/ansible/inventory/script.py index 13b53a24f5..9675d70f69 100644 --- a/v2/ansible/inventory/script.py +++ b/v2/ansible/inventory/script.py @@ -16,6 +16,8 @@ # along with Ansible. If not, see . ############################################# +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import subprocess diff --git a/v2/ansible/inventory/vars_plugins/noop.py b/v2/ansible/inventory/vars_plugins/noop.py index 5d4b4b6658..8f0c98cad5 100644 --- a/v2/ansible/inventory/vars_plugins/noop.py +++ b/v2/ansible/inventory/vars_plugins/noop.py @@ -15,6 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type class VarsModule(object): diff --git a/v2/ansible/parsing/utils/jsonify.py b/v2/ansible/parsing/utils/jsonify.py index 37c97d0195..59dbf9f8c4 100644 --- a/v2/ansible/parsing/utils/jsonify.py +++ b/v2/ansible/parsing/utils/jsonify.py @@ -1,4 +1,23 @@ -# FIXME: header +# (c) 2012-2014, Michael DeHaan +# +# 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 . + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type try: import json diff --git a/v2/ansible/playbook/base.py b/v2/ansible/playbook/base.py index e834d3b729..c6a9d9a051 100644 --- a/v2/ansible/playbook/base.py +++ b/v2/ansible/playbook/base.py @@ -270,9 +270,9 @@ class Base: # and assign the massaged value back to the attribute field setattr(self, name, value) - except (TypeError, ValueError), e: + except (TypeError, ValueError) as e: raise AnsibleParserError("the field '%s' has an invalid value (%s), and could not be converted to an %s. Error was: %s" % (name, value, attribute.isa, e), obj=self.get_ds()) - except UndefinedError, e: + except UndefinedError as e: if fail_on_undefined: raise AnsibleParserError("the field '%s' has an invalid value, which appears to include a variable that is undefined. The error was: %s" % (name,e), obj=self.get_ds()) diff --git a/v2/ansible/playbook/helpers.py b/v2/ansible/playbook/helpers.py index 7242322b88..92f1c64c83 100644 --- a/v2/ansible/playbook/helpers.py +++ b/v2/ansible/playbook/helpers.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/playbook/play.py b/v2/ansible/playbook/play.py index 33fd5efd9f..c7f89888b8 100644 --- a/v2/ansible/playbook/play.py +++ b/v2/ansible/playbook/play.py @@ -16,7 +16,7 @@ # along with Ansible. If not, see . # Make coding more python3-ish -from __future__ import (absolute_import, division) +from __future__ import (absolute_import, division, print_function) __metaclass__ = type from ansible.errors import AnsibleError, AnsibleParserError diff --git a/v2/ansible/plugins/__init__.py b/v2/ansible/plugins/__init__.py index a55059f1b7..d16eecd3c3 100644 --- a/v2/ansible/plugins/__init__.py +++ b/v2/ansible/plugins/__init__.py @@ -180,7 +180,7 @@ class PluginLoader: if os.path.isdir(path): try: full_paths = (os.path.join(path, f) for f in os.listdir(path)) - except OSError,e: + except OSError as e: d = Display() d.warning("Error accessing plugin paths: %s" % str(e)) for full_path in (f for f in full_paths if os.path.isfile(f)): diff --git a/v2/ansible/plugins/action/__init__.py b/v2/ansible/plugins/action/__init__.py index 2f56c4df58..30d1641090 100644 --- a/v2/ansible/plugins/action/__init__.py +++ b/v2/ansible/plugins/action/__init__.py @@ -19,7 +19,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -import StringIO +from six.moves import StringIO import json import os import random @@ -122,7 +122,7 @@ class ActionBase: # FIXME: modified from original, needs testing? Since this is now inside # the action plugin, it should make it just this simple return getattr(self, 'TRANSFERS_FILES', False) - + def _late_needs_tmp_path(self, tmp, module_style): ''' Determines if a temp path is required after some early actions have already taken place. @@ -223,7 +223,7 @@ class ActionBase: #else: # data = data.encode('utf-8') afo.write(data) - except Exception, e: + except Exception as e: #raise AnsibleError("failure encoding into utf-8: %s" % str(e)) raise AnsibleError("failure writing module data to temporary file for transfer: %s" % str(e)) @@ -319,7 +319,7 @@ class ActionBase: filter only leading lines since multiline JSON is valid. ''' - filtered_lines = StringIO.StringIO() + filtered_lines = StringIO() stop_filtering = False for line in data.splitlines(): if stop_filtering or line.startswith('{') or line.startswith('['): diff --git a/v2/ansible/plugins/action/assemble.py b/v2/ansible/plugins/action/assemble.py index 638d4b92bb..4e796bddb6 100644 --- a/v2/ansible/plugins/action/assemble.py +++ b/v2/ansible/plugins/action/assemble.py @@ -15,6 +15,8 @@ # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import os.path diff --git a/v2/ansible/plugins/action/assert.py b/v2/ansible/plugins/action/assert.py index 7204d93875..5c4fdd7b89 100644 --- a/v2/ansible/plugins/action/assert.py +++ b/v2/ansible/plugins/action/assert.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import AnsibleError from ansible.playbook.conditional import Conditional diff --git a/v2/ansible/plugins/action/async.py b/v2/ansible/plugins/action/async.py index 6fbf93d61f..7c02e09757 100644 --- a/v2/ansible/plugins/action/async.py +++ b/v2/ansible/plugins/action/async.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import json import random diff --git a/v2/ansible/plugins/action/copy.py b/v2/ansible/plugins/action/copy.py index ece8b5b11b..6db130ad7f 100644 --- a/v2/ansible/plugins/action/copy.py +++ b/v2/ansible/plugins/action/copy.py @@ -70,7 +70,7 @@ class ActionModule(ActionBase): else: content_tempfile = self._create_content_tempfile(content) source = content_tempfile - except Exception, err: + except Exception as err: return dict(failed=True, msg="could not write content temp file: %s" % err) ############################################################################################### @@ -270,7 +270,7 @@ class ActionModule(ActionBase): if module_return.get('changed') == True: changed = True - # the file module returns the file path as 'path', but + # the file module returns the file path as 'path', but # the copy module uses 'dest', so add it if it's not there if 'path' in module_return and 'dest' not in module_return: module_return['dest'] = module_return['path'] @@ -297,7 +297,7 @@ class ActionModule(ActionBase): content = to_bytes(content) try: f.write(content) - except Exception, err: + except Exception as err: os.remove(content_tempfile) raise Exception(err) finally: diff --git a/v2/ansible/plugins/action/debug.py b/v2/ansible/plugins/action/debug.py index dcee3e6347..dc80dfc179 100644 --- a/v2/ansible/plugins/action/debug.py +++ b/v2/ansible/plugins/action/debug.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.action import ActionBase from ansible.utils.boolean import boolean diff --git a/v2/ansible/plugins/action/fail.py b/v2/ansible/plugins/action/fail.py index a95ccb32f7..b7845c95c5 100644 --- a/v2/ansible/plugins/action/fail.py +++ b/v2/ansible/plugins/action/fail.py @@ -15,6 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.action import ActionBase diff --git a/v2/ansible/plugins/action/fetch.py b/v2/ansible/plugins/action/fetch.py index 7b549f5ecb..58e7cebb8d 100644 --- a/v2/ansible/plugins/action/fetch.py +++ b/v2/ansible/plugins/action/fetch.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import pwd diff --git a/v2/ansible/plugins/action/group_by.py b/v2/ansible/plugins/action/group_by.py index 50e0cc09c4..95db33aa43 100644 --- a/v2/ansible/plugins/action/group_by.py +++ b/v2/ansible/plugins/action/group_by.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import * from ansible.plugins.action import ActionBase diff --git a/v2/ansible/plugins/action/include_vars.py b/v2/ansible/plugins/action/include_vars.py index 345e0edc0e..8a7a74d870 100644 --- a/v2/ansible/plugins/action/include_vars.py +++ b/v2/ansible/plugins/action/include_vars.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/plugins/action/normal.py b/v2/ansible/plugins/action/normal.py index 66721b4eb2..431d9b0eeb 100644 --- a/v2/ansible/plugins/action/normal.py +++ b/v2/ansible/plugins/action/normal.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.action import ActionBase diff --git a/v2/ansible/plugins/action/pause.py b/v2/ansible/plugins/action/pause.py index 9c6075e101..c5a97d5366 100644 --- a/v2/ansible/plugins/action/pause.py +++ b/v2/ansible/plugins/action/pause.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import datetime import sys @@ -68,7 +70,7 @@ class ActionModule(ActionBase): seconds = int(self._task.args['seconds']) duration_unit = 'seconds' - except ValueError, e: + except ValueError as e: return dict(failed=True, msg="non-integer value given for prompt duration:\n%s" % str(e)) # Is 'prompt' a key in 'args'? @@ -99,7 +101,7 @@ class ActionModule(ActionBase): try: if not pause_type == 'prompt': - print "(^C-c = continue early, ^C-a = abort)" + print("(^C-c = continue early, ^C-a = abort)") #print("[%s]\nPausing for %s seconds" % (hosts, seconds)) print("[%s]\nPausing for %s seconds" % (self._task.get_name().strip(), seconds)) time.sleep(seconds) @@ -110,7 +112,7 @@ class ActionModule(ActionBase): result['user_input'] = raw_input(prompt.encode(sys.stdout.encoding)) except KeyboardInterrupt: while True: - print '\nAction? (a)bort/(c)ontinue: ' + print('\nAction? (a)bort/(c)ontinue: ') c = getch() if c == 'c': # continue playbook evaluation diff --git a/v2/ansible/plugins/action/raw.py b/v2/ansible/plugins/action/raw.py index d1d1b28056..f9cd56572b 100644 --- a/v2/ansible/plugins/action/raw.py +++ b/v2/ansible/plugins/action/raw.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.action import ActionBase diff --git a/v2/ansible/plugins/action/script.py b/v2/ansible/plugins/action/script.py index 21a9f41c59..3ca7dc6a34 100644 --- a/v2/ansible/plugins/action/script.py +++ b/v2/ansible/plugins/action/script.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/plugins/action/set_fact.py b/v2/ansible/plugins/action/set_fact.py index bf89e7ec51..a7ddf10b47 100644 --- a/v2/ansible/plugins/action/set_fact.py +++ b/v2/ansible/plugins/action/set_fact.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import AnsibleError from ansible.plugins.action import ActionBase diff --git a/v2/ansible/plugins/action/synchronize.py b/v2/ansible/plugins/action/synchronize.py index 81e335b009..1bc64ff4d5 100644 --- a/v2/ansible/plugins/action/synchronize.py +++ b/v2/ansible/plugins/action/synchronize.py @@ -15,6 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os.path diff --git a/v2/ansible/plugins/action/template.py b/v2/ansible/plugins/action/template.py index 76b2e78a73..a234ef2eee 100644 --- a/v2/ansible/plugins/action/template.py +++ b/v2/ansible/plugins/action/template.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import base64 import os @@ -102,7 +104,7 @@ class ActionModule(ActionBase): with open(source, 'r') as f: template_data = f.read() resultant = templar.template(template_data, preserve_trailing_newlines=True) - except Exception, e: + except Exception as e: return dict(failed=True, msg=type(e).__name__ + ": " + str(e)) local_checksum = checksum_s(resultant) diff --git a/v2/ansible/plugins/action/unarchive.py b/v2/ansible/plugins/action/unarchive.py index 1b6cb354f0..b7601ed910 100644 --- a/v2/ansible/plugins/action/unarchive.py +++ b/v2/ansible/plugins/action/unarchive.py @@ -15,6 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import pipes diff --git a/v2/ansible/plugins/cache/__init__.py b/v2/ansible/plugins/cache/__init__.py index deed7f3ecd..4aa8fda8bb 100644 --- a/v2/ansible/plugins/cache/__init__.py +++ b/v2/ansible/plugins/cache/__init__.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from collections import MutableMapping diff --git a/v2/ansible/plugins/cache/base.py b/v2/ansible/plugins/cache/base.py index b6254cdfd4..6ff3d5ed1e 100644 --- a/v2/ansible/plugins/cache/base.py +++ b/v2/ansible/plugins/cache/base.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import exceptions diff --git a/v2/ansible/plugins/cache/memcached.py b/v2/ansible/plugins/cache/memcached.py index deaf07fe2e..e7321a5a6b 100644 --- a/v2/ansible/plugins/cache/memcached.py +++ b/v2/ansible/plugins/cache/memcached.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import collections import os @@ -28,7 +30,7 @@ from ansible.plugins.cache.base import BaseCacheModule try: import memcache except ImportError: - print 'python-memcached is required for the memcached fact cache' + print('python-memcached is required for the memcached fact cache') sys.exit(1) diff --git a/v2/ansible/plugins/cache/memory.py b/v2/ansible/plugins/cache/memory.py index 007719a647..1562836151 100644 --- a/v2/ansible/plugins/cache/memory.py +++ b/v2/ansible/plugins/cache/memory.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.cache.base import BaseCacheModule diff --git a/v2/ansible/plugins/cache/redis.py b/v2/ansible/plugins/cache/redis.py index 7f126de64b..287c14bd2a 100644 --- a/v2/ansible/plugins/cache/redis.py +++ b/v2/ansible/plugins/cache/redis.py @@ -14,9 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type -from __future__ import absolute_import -import collections # FIXME: can we store these as something else before we ship it? import sys import time @@ -28,7 +28,7 @@ from ansible.plugins.cache.base import BaseCacheModule try: from redis import StrictRedis except ImportError: - print "The 'redis' python module is required, 'pip install redis'" + print("The 'redis' python module is required, 'pip install redis'") sys.exit(1) class CacheModule(BaseCacheModule): diff --git a/v2/ansible/plugins/connections/accelerate.py b/v2/ansible/plugins/connections/accelerate.py index a31124e119..78e2630eff 100644 --- a/v2/ansible/plugins/connections/accelerate.py +++ b/v2/ansible/plugins/connections/accelerate.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import json import os @@ -140,7 +142,7 @@ class Connection(object): # shutdown, so we'll reconnect. wrong_user = True - except AnsibleError, e: + except AnsibleError as e: if allow_ssh: if "WRONG_USER" in e: vvv("Switching users, waiting for the daemon on %s to shutdown completely..." % self.host) diff --git a/v2/ansible/plugins/connections/chroot.py b/v2/ansible/plugins/connections/chroot.py index 38c8af7a69..4e61f4ea55 100644 --- a/v2/ansible/plugins/connections/chroot.py +++ b/v2/ansible/plugins/connections/chroot.py @@ -15,6 +15,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import distutils.spawn import traceback diff --git a/v2/ansible/plugins/connections/funcd.py b/v2/ansible/plugins/connections/funcd.py index 7244abcbe9..83a0c9b01d 100644 --- a/v2/ansible/plugins/connections/funcd.py +++ b/v2/ansible/plugins/connections/funcd.py @@ -18,6 +18,9 @@ # along with Ansible. If not, see . # --- +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + # The func transport permit to use ansible over func. For people who have already setup # func and that wish to play with ansible, this permit to move gradually to ansible # without having to redo completely the setup of the network. diff --git a/v2/ansible/plugins/connections/jail.py b/v2/ansible/plugins/connections/jail.py index b721ad62b5..a81f587bfd 100644 --- a/v2/ansible/plugins/connections/jail.py +++ b/v2/ansible/plugins/connections/jail.py @@ -16,6 +16,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import distutils.spawn import traceback diff --git a/v2/ansible/plugins/connections/libvirt_lxc.py b/v2/ansible/plugins/connections/libvirt_lxc.py index c6cf11f266..ee824554a0 100644 --- a/v2/ansible/plugins/connections/libvirt_lxc.py +++ b/v2/ansible/plugins/connections/libvirt_lxc.py @@ -16,6 +16,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import distutils.spawn import os diff --git a/v2/ansible/plugins/connections/local.py b/v2/ansible/plugins/connections/local.py index 31d0b296e4..73583974bf 100644 --- a/v2/ansible/plugins/connections/local.py +++ b/v2/ansible/plugins/connections/local.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import traceback import os diff --git a/v2/ansible/plugins/connections/paramiko_ssh.py b/v2/ansible/plugins/connections/paramiko_ssh.py index 4bb06e01c3..167b0d39a8 100644 --- a/v2/ansible/plugins/connections/paramiko_ssh.py +++ b/v2/ansible/plugins/connections/paramiko_ssh.py @@ -14,7 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . - +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # --- # The paramiko transport is provided because many distributions, in particular EL6 and before @@ -170,7 +171,7 @@ class Connection(object): key_filename=key_filename, password=self.password, timeout=self.runner.timeout, port=self.port) - except Exception, e: + except Exception as e: msg = str(e) if "PID check failed" in msg: @@ -197,7 +198,7 @@ class Connection(object): self.ssh.get_transport().set_keepalive(5) chan = self.ssh.get_transport().open_session() - except Exception, e: + except Exception as e: msg = "Failed to open session" if len(str(e)) > 0: @@ -284,7 +285,7 @@ class Connection(object): try: self.sftp = self.ssh.open_sftp() - except Exception, e: + except Exception as e: raise errors.AnsibleError("failed to open a SFTP connection (%s)" % e) try: @@ -308,7 +309,7 @@ class Connection(object): try: self.sftp = self._connect_sftp() - except Exception, e: + except Exception as e: raise errors.AnsibleError("failed to open a SFTP connection (%s)", e) try: diff --git a/v2/ansible/plugins/connections/ssh.py b/v2/ansible/plugins/connections/ssh.py index e59311ead9..2c8f8de813 100644 --- a/v2/ansible/plugins/connections/ssh.py +++ b/v2/ansible/plugins/connections/ssh.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . # +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import re diff --git a/v2/ansible/plugins/connections/winrm.py b/v2/ansible/plugins/connections/winrm.py index d6e51710b5..f94141b81b 100644 --- a/v2/ansible/plugins/connections/winrm.py +++ b/v2/ansible/plugins/connections/winrm.py @@ -14,8 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . - -from __future__ import absolute_import +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import base64 import hashlib @@ -147,7 +147,7 @@ class Connection(object): cmd_parts = powershell._encode_script(script, as_list=True) try: result = self._winrm_exec(cmd_parts[0], cmd_parts[1:], from_exec=True) - except Exception, e: + except Exception as e: traceback.print_exc() raise errors.AnsibleError("failed to exec cmd %s" % cmd) return (result.status_code, '', result.std_out.encode('utf-8'), result.std_err.encode('utf-8')) diff --git a/v2/ansible/plugins/inventory/directory.py b/v2/ansible/plugins/inventory/directory.py index d340ed7538..a75ad44ea6 100644 --- a/v2/ansible/plugins/inventory/directory.py +++ b/v2/ansible/plugins/inventory/directory.py @@ -18,7 +18,7 @@ ############################################# # Make coding more python3-ish -from __future__ import (division, print_function) +from __future__ import (absolute_import, division, print_function) __metaclass__ = type import os diff --git a/v2/ansible/plugins/lookup/cartesian.py b/v2/ansible/plugins/lookup/cartesian.py index cc74240826..c50d53e7f8 100644 --- a/v2/ansible/plugins/lookup/cartesian.py +++ b/v2/ansible/plugins/lookup/cartesian.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from itertools import product diff --git a/v2/ansible/plugins/lookup/csvfile.py b/v2/ansible/plugins/lookup/csvfile.py index 87757399ce..2a98d19fe4 100644 --- a/v2/ansible/plugins/lookup/csvfile.py +++ b/v2/ansible/plugins/lookup/csvfile.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import codecs @@ -33,7 +35,7 @@ class LookupModule(LookupBase): for row in creader: if row[0] == key: return row[int(col)] - except Exception, e: + except Exception as e: raise AnsibleError("csvfile: %s" % str(e)) return dflt @@ -61,7 +63,7 @@ class LookupModule(LookupBase): name, value = param.split('=') assert(name in paramvals) paramvals[name] = value - except (ValueError, AssertionError), e: + except (ValueError, AssertionError) as e: raise AnsibleError(e) if paramvals['delimiter'] == 'TAB': diff --git a/v2/ansible/plugins/lookup/dict.py b/v2/ansible/plugins/lookup/dict.py index 61389df7c2..cc7975ae49 100644 --- a/v2/ansible/plugins/lookup/dict.py +++ b/v2/ansible/plugins/lookup/dict.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/dnstxt.py b/v2/ansible/plugins/lookup/dnstxt.py index 7100f8d96d..e9dd27bfb6 100644 --- a/v2/ansible/plugins/lookup/dnstxt.py +++ b/v2/ansible/plugins/lookup/dnstxt.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os @@ -59,7 +61,7 @@ class LookupModule(LookupBase): string = 'NXDOMAIN' except dns.resolver.Timeout: string = '' - except dns.exception.DNSException, e: + except dns.exception.DNSException as e: raise AnsibleError("dns.resolver unhandled exception", e) ret.append(''.join(string)) diff --git a/v2/ansible/plugins/lookup/env.py b/v2/ansible/plugins/lookup/env.py index 896f95e13a..55847dd777 100644 --- a/v2/ansible/plugins/lookup/env.py +++ b/v2/ansible/plugins/lookup/env.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/plugins/lookup/etcd.py b/v2/ansible/plugins/lookup/etcd.py index 5b54788985..002068389f 100644 --- a/v2/ansible/plugins/lookup/etcd.py +++ b/v2/ansible/plugins/lookup/etcd.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import urllib2 diff --git a/v2/ansible/plugins/lookup/file.py b/v2/ansible/plugins/lookup/file.py index add4da7f47..efb039497d 100644 --- a/v2/ansible/plugins/lookup/file.py +++ b/v2/ansible/plugins/lookup/file.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import codecs diff --git a/v2/ansible/plugins/lookup/fileglob.py b/v2/ansible/plugins/lookup/fileglob.py index bde016af9e..8985906715 100644 --- a/v2/ansible/plugins/lookup/fileglob.py +++ b/v2/ansible/plugins/lookup/fileglob.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import glob diff --git a/v2/ansible/plugins/lookup/first_found.py b/v2/ansible/plugins/lookup/first_found.py index 0ed2688015..091f104c62 100644 --- a/v2/ansible/plugins/lookup/first_found.py +++ b/v2/ansible/plugins/lookup/first_found.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type # take a list of files and (optionally) a list of paths # return the first existing file found in the paths @@ -177,7 +179,7 @@ class LookupModule(LookupBase): for fn in total_search: try: fn = templar.template(fn) - except (AnsibleUndefinedVariable, UndefinedError), e: + except (AnsibleUndefinedVariable, UndefinedError) as e: continue if os.path.isabs(fn) and os.path.exists(fn): diff --git a/v2/ansible/plugins/lookup/flattened.py b/v2/ansible/plugins/lookup/flattened.py index 24f1a9ac95..f0a8adaf5e 100644 --- a/v2/ansible/plugins/lookup/flattened.py +++ b/v2/ansible/plugins/lookup/flattened.py @@ -14,7 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . - +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import * from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/indexed_items.py b/v2/ansible/plugins/lookup/indexed_items.py index 1731dc0e84..4f1dd19947 100644 --- a/v2/ansible/plugins/lookup/indexed_items.py +++ b/v2/ansible/plugins/lookup/indexed_items.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/inventory_hostnames.py b/v2/ansible/plugins/lookup/inventory_hostnames.py index faffe47eb8..d09dec0c7b 100644 --- a/v2/ansible/plugins/lookup/inventory_hostnames.py +++ b/v2/ansible/plugins/lookup/inventory_hostnames.py @@ -16,6 +16,9 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + from ansible.errors import * from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/items.py b/v2/ansible/plugins/lookup/items.py index 46925d2a8b..65ff66d854 100644 --- a/v2/ansible/plugins/lookup/items.py +++ b/v2/ansible/plugins/lookup/items.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/lines.py b/v2/ansible/plugins/lookup/lines.py index 507793b18e..0d842bf148 100644 --- a/v2/ansible/plugins/lookup/lines.py +++ b/v2/ansible/plugins/lookup/lines.py @@ -15,8 +15,10 @@ # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . -import subprocess +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type +import subprocess from ansible.errors import * from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/nested.py b/v2/ansible/plugins/lookup/nested.py index 0f2d146b47..52f4bed1d5 100644 --- a/v2/ansible/plugins/lookup/nested.py +++ b/v2/ansible/plugins/lookup/nested.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import AnsibleError from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/password.py b/v2/ansible/plugins/lookup/password.py index 6e13410e1a..2e7633a067 100644 --- a/v2/ansible/plugins/lookup/password.py +++ b/v2/ansible/plugins/lookup/password.py @@ -16,6 +16,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import errno @@ -85,7 +87,7 @@ class LookupModule(LookupBase): paramvals['chars'] = use_chars else: paramvals[name] = value - except (ValueError, AssertionError), e: + except (ValueError, AssertionError) as e: raise AnsibleError(e) length = paramvals['length'] @@ -98,8 +100,8 @@ class LookupModule(LookupBase): pathdir = os.path.dirname(path) if not os.path.isdir(pathdir): try: - os.makedirs(pathdir, mode=0700) - except OSError, e: + os.makedirs(pathdir, mode=0o700) + except OSError as e: raise AnsibleError("cannot create the path for the password lookup: %s (error was %s)" % (pathdir, str(e))) chars = "".join([getattr(string,c,c) for c in use_chars]).replace('"','').replace("'",'') @@ -111,7 +113,7 @@ class LookupModule(LookupBase): else: content = password with open(path, 'w') as f: - os.chmod(path, 0600) + os.chmod(path, 0o600) f.write(content + '\n') else: content = open(path).read().rstrip() @@ -129,12 +131,12 @@ class LookupModule(LookupBase): salt = self.random_salt() content = '%s salt=%s' % (password, salt) with open(path, 'w') as f: - os.chmod(path, 0600) + os.chmod(path, 0o600) f.write(content + '\n') # crypt not requested, remove salt if present elif (encrypt is None and salt): with open(path, 'w') as f: - os.chmod(path, 0600) + os.chmod(path, 0o600) f.write(password + '\n') if encrypt: diff --git a/v2/ansible/plugins/lookup/pipe.py b/v2/ansible/plugins/lookup/pipe.py index 0a7e5cb31a..d9f74708b2 100644 --- a/v2/ansible/plugins/lookup/pipe.py +++ b/v2/ansible/plugins/lookup/pipe.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import subprocess diff --git a/v2/ansible/plugins/lookup/random_choice.py b/v2/ansible/plugins/lookup/random_choice.py index e899a2dbe3..de4f31cd0e 100644 --- a/v2/ansible/plugins/lookup/random_choice.py +++ b/v2/ansible/plugins/lookup/random_choice.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import random diff --git a/v2/ansible/plugins/lookup/redis_kv.py b/v2/ansible/plugins/lookup/redis_kv.py index 08895d4c4e..e499e83f93 100644 --- a/v2/ansible/plugins/lookup/redis_kv.py +++ b/v2/ansible/plugins/lookup/redis_kv.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import re diff --git a/v2/ansible/plugins/lookup/sequence.py b/v2/ansible/plugins/lookup/sequence.py index 99783cf566..1ddeba932f 100644 --- a/v2/ansible/plugins/lookup/sequence.py +++ b/v2/ansible/plugins/lookup/sequence.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from re import compile as re_compile, IGNORECASE diff --git a/v2/ansible/plugins/lookup/subelements.py b/v2/ansible/plugins/lookup/subelements.py index 93e9e570c4..09a2ca306a 100644 --- a/v2/ansible/plugins/lookup/subelements.py +++ b/v2/ansible/plugins/lookup/subelements.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.errors import * from ansible.plugins.lookup import LookupBase diff --git a/v2/ansible/plugins/lookup/template.py b/v2/ansible/plugins/lookup/template.py index 74406f6445..e53e1990a0 100644 --- a/v2/ansible/plugins/lookup/template.py +++ b/v2/ansible/plugins/lookup/template.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os diff --git a/v2/ansible/plugins/lookup/together.py b/v2/ansible/plugins/lookup/together.py index 8b5ff5c891..2f53121cc8 100644 --- a/v2/ansible/plugins/lookup/together.py +++ b/v2/ansible/plugins/lookup/together.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from itertools import izip_longest diff --git a/v2/ansible/plugins/lookup/url.py b/v2/ansible/plugins/lookup/url.py index c907bfbce3..4361b1192d 100644 --- a/v2/ansible/plugins/lookup/url.py +++ b/v2/ansible/plugins/lookup/url.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.plugins.lookup import LookupBase import urllib2 @@ -31,10 +33,10 @@ class LookupModule(LookupBase): try: r = urllib2.Request(term) response = urllib2.urlopen(r) - except URLError, e: + except URLError as e: utils.warnings("Failed lookup url for %s : %s" % (term, str(e))) continue - except HTTPError, e: + except HTTPError as e: utils.warnings("Recieved HTTP error for %s : %s" % (term, str(e))) continue diff --git a/v2/ansible/plugins/shell/csh.py b/v2/ansible/plugins/shell/csh.py index 4e9f8c8af7..96ec84c5bf 100644 --- a/v2/ansible/plugins/shell/csh.py +++ b/v2/ansible/plugins/shell/csh.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.runner.shell_plugins.sh import ShellModule as ShModule diff --git a/v2/ansible/plugins/shell/fish.py b/v2/ansible/plugins/shell/fish.py index 137c013c12..53fa9abada 100644 --- a/v2/ansible/plugins/shell/fish.py +++ b/v2/ansible/plugins/shell/fish.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type from ansible.runner.shell_plugins.sh import ShellModule as ShModule diff --git a/v2/ansible/plugins/shell/powershell.py b/v2/ansible/plugins/shell/powershell.py index 7254df6f7e..9f3825c3b0 100644 --- a/v2/ansible/plugins/shell/powershell.py +++ b/v2/ansible/plugins/shell/powershell.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import base64 import os diff --git a/v2/ansible/plugins/shell/sh.py b/v2/ansible/plugins/shell/sh.py index 5fb0dc3add..497d45eace 100644 --- a/v2/ansible/plugins/shell/sh.py +++ b/v2/ansible/plugins/shell/sh.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import re diff --git a/v2/ansible/plugins/strategies/__init__.py b/v2/ansible/plugins/strategies/__init__.py index afbc373f4f..c5b3dd0f06 100644 --- a/v2/ansible/plugins/strategies/__init__.py +++ b/v2/ansible/plugins/strategies/__init__.py @@ -109,7 +109,7 @@ class StrategyBase: self._pending_results += 1 main_q.put((host, task, self._loader.get_basedir(), task_vars, connection_info, module_loader), block=False) - except (EOFError, IOError, AssertionError), e: + except (EOFError, IOError, AssertionError) as e: # most likely an abort debug("got an error while queuing: %s" % e) return diff --git a/v2/ansible/plugins/strategies/free.py b/v2/ansible/plugins/strategies/free.py index 4fd8a13201..d0506d37dd 100644 --- a/v2/ansible/plugins/strategies/free.py +++ b/v2/ansible/plugins/strategies/free.py @@ -139,7 +139,7 @@ class StrategyModule(StrategyBase): try: results = self._wait_on_pending_results(iterator) host_results.extend(results) - except Exception, e: + except Exception as e: # FIXME: ctrl+c can cause some failures here, so catch them # with the appropriate error type print("wtf: %s" % e) diff --git a/v2/ansible/template/__init__.py b/v2/ansible/template/__init__.py index 0345a75008..6c41ad3cf4 100644 --- a/v2/ansible/template/__init__.py +++ b/v2/ansible/template/__init__.py @@ -19,6 +19,8 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type +import re + from jinja2 import Environment from jinja2.exceptions import TemplateSyntaxError, UndefinedError from jinja2.utils import concat as j2_concat @@ -141,8 +143,8 @@ class Templar: only_one = SINGLE_VAR.match(variable) if only_one: var_name = only_one.group(1) - if var_name in self._available_vars: - resolved_val = self._available_vars[var_name] + if var_name in self._available_variables: + resolved_val = self._available_variables[var_name] if isinstance(resolved_val, NON_TEMPLATED_TYPES): return resolved_val diff --git a/v2/ansible/template/safe_eval.py b/v2/ansible/template/safe_eval.py index ba377054d7..81db8b2333 100644 --- a/v2/ansible/template/safe_eval.py +++ b/v2/ansible/template/safe_eval.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import ast import sys @@ -105,13 +107,13 @@ def safe_eval(expr, locals={}, include_exceptions=False): return (result, None) else: return result - except SyntaxError, e: + except SyntaxError as e: # special handling for syntax errors, we just return # the expression string back as-is if include_exceptions: return (expr, None) return expr - except Exception, e: + except Exception as e: if include_exceptions: return (expr, e) return expr diff --git a/v2/ansible/utils/color.py b/v2/ansible/utils/color.py index a87717073e..37d0466d2d 100644 --- a/v2/ansible/utils/color.py +++ b/v2/ansible/utils/color.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import sys diff --git a/v2/ansible/utils/debug.py b/v2/ansible/utils/debug.py index 3b37ac50a7..5b04ac0572 100644 --- a/v2/ansible/utils/debug.py +++ b/v2/ansible/utils/debug.py @@ -1,3 +1,6 @@ +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + import os import time import sys diff --git a/v2/ansible/utils/display.py b/v2/ansible/utils/display.py index 62dbeabca5..f132d4383f 100644 --- a/v2/ansible/utils/display.py +++ b/v2/ansible/utils/display.py @@ -16,6 +16,8 @@ # along with Ansible. If not, see . # FIXME: copied mostly from old code, needs py3 improvements +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import textwrap import sys @@ -41,14 +43,14 @@ class Display: if not log_only: if not stderr: try: - print msg2 + print(msg2) except UnicodeEncodeError: - print msg2.encode('utf-8') + print(msg2.encode('utf-8')) else: try: - print >>sys.stderr, msg2 + print(msg2, file=sys.stderr) except UnicodeEncodeError: - print >>sys.stderr, msg2.encode('utf-8') + print(msg2.encode('utf-8'), file=sys.stderr) if C.DEFAULT_LOG_PATH != '': while msg.startswith("\n"): msg = msg.replace("\n","") diff --git a/v2/ansible/utils/encrypt.py b/v2/ansible/utils/encrypt.py index 878b461c86..5138dbef70 100644 --- a/v2/ansible/utils/encrypt.py +++ b/v2/ansible/utils/encrypt.py @@ -14,6 +14,9 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + PASSLIB_AVAILABLE = False try: diff --git a/v2/ansible/utils/hashing.py b/v2/ansible/utils/hashing.py index 0b2edd434b..2c7dd534fc 100644 --- a/v2/ansible/utils/hashing.py +++ b/v2/ansible/utils/hashing.py @@ -64,7 +64,7 @@ def secure_hash(filename, hash_func=sha1): digest.update(block) block = infile.read(blocksize) infile.close() - except IOError, e: + except IOError as e: raise errors.AnsibleError("error while accessing the file %s, error was: %s" % (filename, e)) return digest.hexdigest() diff --git a/v2/ansible/utils/path.py b/v2/ansible/utils/path.py index ea7fc201a8..e49a2f7d55 100644 --- a/v2/ansible/utils/path.py +++ b/v2/ansible/utils/path.py @@ -14,6 +14,8 @@ # # You should have received a copy of the GNU General Public License # along with Ansible. If not, see . +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type import os import stat diff --git a/v2/ansible/utils/vault.py b/v2/ansible/utils/vault.py index 04634aa377..5c704afac5 100644 --- a/v2/ansible/utils/vault.py +++ b/v2/ansible/utils/vault.py @@ -40,7 +40,7 @@ def read_vault_file(vault_password_file): try: # STDERR not captured to make it easier for users to prompt for input in their scripts p = subprocess.Popen(this_path, stdout=subprocess.PIPE) - except OSError, e: + except OSError as e: raise AnsibleError("Problem running vault password script %s (%s). If this is not a script, remove the executable bit from the file." % (' '.join(this_path), e)) stdout, stderr = p.communicate() vault_pass = stdout.strip('\r\n') @@ -49,7 +49,7 @@ def read_vault_file(vault_password_file): f = open(this_path, "rb") vault_pass=f.read().strip() f.close() - except (OSError, IOError), e: + except (OSError, IOError) as e: raise AnsibleError("Could not read vault password file %s: %s" % (this_path, e)) return vault_pass diff --git a/v2/ansible/vars/__init__.py b/v2/ansible/vars/__init__.py index eb75d9c992..183116ea2d 100644 --- a/v2/ansible/vars/__init__.py +++ b/v2/ansible/vars/__init__.py @@ -243,7 +243,7 @@ class VariableManager: try: names = loader.list_directory(path) - except os.error, err: + except os.error as err: raise AnsibleError("This folder cannot be listed: %s: %s." % (path, err.strerror)) # evaluate files in a stable order rather than whatever diff --git a/v2/samples/multi.py b/v2/samples/multi.py index ca4c8b68f7..dce6143059 100644 --- a/v2/samples/multi.py +++ b/v2/samples/multi.py @@ -59,10 +59,10 @@ def results(pipe, workers): time.sleep(0.01) continue pipe.send(result) - except (IOError, EOFError, KeyboardInterrupt), e: + except (IOError, EOFError, KeyboardInterrupt) as e: debug("got a breaking error: %s" % e) break - except Exception, e: + except Exception as e: debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e) traceback.print_exc() break diff --git a/v2/samples/multi_queues.py b/v2/samples/multi_queues.py index 8eb8036607..9e8f22b9a9 100644 --- a/v2/samples/multi_queues.py +++ b/v2/samples/multi_queues.py @@ -55,10 +55,10 @@ def results(final_q, workers): time.sleep(0.01) continue final_q.put(result, block=False) - except (IOError, EOFError, KeyboardInterrupt), e: + except (IOError, EOFError, KeyboardInterrupt) as e: debug("got a breaking error: %s" % e) break - except Exception, e: + except Exception as e: debug("EXCEPTION DURING RESULTS PROCESSING: %s" % e) traceback.print_exc() break @@ -77,10 +77,10 @@ def worker(main_q, res_q, loader): time.sleep(0.01) except Queue.Empty: pass - except (IOError, EOFError, KeyboardInterrupt), e: + except (IOError, EOFError, KeyboardInterrupt) as e: debug("got a breaking error: %s" % e) break - except Exception, e: + except Exception as e: debug("EXCEPTION DURING WORKER PROCESSING: %s" % e) traceback.print_exc() break diff --git a/v2/setup.py b/v2/setup.py new file mode 100644 index 0000000000..a9a5187981 --- /dev/null +++ b/v2/setup.py @@ -0,0 +1,36 @@ +#!/usr/bin/env python + +import sys + +from ansible import __version__ +try: + from setuptools import setup, find_packages +except ImportError: + print("Ansible now needs setuptools in order to build. Install it using" + " your package manager (usually python-setuptools) or via pip (pip" + " install setuptools).") + sys.exit(1) + +setup(name='ansible', + version=__version__, + description='Radically simple IT automation', + author='Michael DeHaan', + author_email='michael@ansible.com', + url='http://ansible.com/', + license='GPLv3', + install_requires=['paramiko', 'jinja2', "PyYAML", 'setuptools', 'pycrypto >= 2.6'], + # package_dir={ '': 'lib' }, + # packages=find_packages('lib'), + package_data={ + '': ['module_utils/*.ps1', 'modules/core/windows/*.ps1', 'modules/extras/windows/*.ps1'], + }, + scripts=[ + 'bin/ansible', + 'bin/ansible-playbook', + # 'bin/ansible-pull', + # 'bin/ansible-doc', + # 'bin/ansible-galaxy', + # 'bin/ansible-vault', + ], + data_files=[], +) diff --git a/v2/test/parsing/yaml/test_loader.py b/v2/test/parsing/yaml/test_loader.py index 9a4746b99d..d393d72a00 100644 --- a/v2/test/parsing/yaml/test_loader.py +++ b/v2/test/parsing/yaml/test_loader.py @@ -20,7 +20,7 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type -from StringIO import StringIO +from six.moves import StringIO from collections import Sequence, Set, Mapping from ansible.compat.tests import unittest