mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge remote-tracking branch 'upstream/devel' into devel
This commit is contained in:
commit
bd4c30b807
95 changed files with 302 additions and 92 deletions
|
@ -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?
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
||||
|
|
|
@ -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::
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division)
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import signal
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#############################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import fnmatch
|
||||
import os
|
||||
import sys
|
||||
|
|
|
@ -17,6 +17,8 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#############################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.utils.debug import debug
|
||||
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#############################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import ast
|
||||
import shlex
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#############################################
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import subprocess
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
class VarsModule(object):
|
||||
|
||||
|
|
|
@ -1,4 +1,23 @@
|
|||
# FIXME: header
|
||||
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
||||
#
|
||||
# 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/>.
|
||||
|
||||
# Make coding more python3-ish
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
try:
|
||||
import json
|
||||
|
|
|
@ -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())
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# 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
|
||||
|
|
|
@ -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)):
|
||||
|
|
|
@ -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('['):
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.playbook.conditional import Conditional
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import json
|
||||
import random
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
from ansible.utils.boolean import boolean
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import pwd
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import *
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.action import ActionBase
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os.path
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import pipes
|
||||
|
|
2
v2/ansible/plugins/cache/__init__.py
vendored
2
v2/ansible/plugins/cache/__init__.py
vendored
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from collections import MutableMapping
|
||||
|
||||
|
|
2
v2/ansible/plugins/cache/base.py
vendored
2
v2/ansible/plugins/cache/base.py
vendored
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import exceptions
|
||||
|
||||
|
|
4
v2/ansible/plugins/cache/memcached.py
vendored
4
v2/ansible/plugins/cache/memcached.py
vendored
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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)
|
||||
|
||||
|
||||
|
|
2
v2/ansible/plugins/cache/memory.py
vendored
2
v2/ansible/plugins/cache/memory.py
vendored
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.cache.base import BaseCacheModule
|
||||
|
||||
|
|
6
v2/ansible/plugins/cache/redis.py
vendored
6
v2/ansible/plugins/cache/redis.py
vendored
|
@ -14,9 +14,9 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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):
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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)
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import distutils.spawn
|
||||
import traceback
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# ---
|
||||
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.
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import distutils.spawn
|
||||
import traceback
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import distutils.spawn
|
||||
import os
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import traceback
|
||||
import os
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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:
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
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'))
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from itertools import product
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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':
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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))
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import urllib2
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import codecs
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import glob
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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):
|
||||
|
|
|
@ -14,7 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import *
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import *
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
|
|
@ -15,8 +15,10 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
import subprocess
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import subprocess
|
||||
from ansible.errors import *
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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:
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import subprocess
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import random
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from re import compile as re_compile, IGNORECASE
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.errors import *
|
||||
from ansible.plugins.lookup import LookupBase
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from itertools import izip_longest
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.runner.shell_plugins.sh import ShellModule as ShModule
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
from ansible.runner.shell_plugins.sh import ShellModule as ShModule
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import base64
|
||||
import os
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import re
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
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
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import sys
|
||||
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import time
|
||||
import sys
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
# 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","")
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
|
||||
PASSLIB_AVAILABLE = False
|
||||
try:
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -14,6 +14,8 @@
|
|||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import os
|
||||
import stat
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
36
v2/setup.py
Normal file
36
v2/setup.py
Normal file
|
@ -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=[],
|
||||
)
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue