2015-06-15 04:35:53 +02:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
2014-11-14 23:14:08 +01:00
|
|
|
|
# (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
|
|
|
|
|
|
2016-07-07 06:09:07 +02:00
|
|
|
|
import os
|
|
|
|
|
import pwd
|
2014-11-14 23:14:08 +01:00
|
|
|
|
import random
|
2015-06-15 04:35:53 +02:00
|
|
|
|
import re
|
2015-09-18 07:52:26 +02:00
|
|
|
|
import string
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-10-16 02:55:23 +02:00
|
|
|
|
from ansible.compat.six import iteritems, string_types
|
2016-11-17 22:18:29 +01:00
|
|
|
|
from ansible.compat.six.moves import shlex_quote
|
2014-11-14 23:14:08 +01:00
|
|
|
|
from ansible import constants as C
|
2015-07-21 18:12:22 +02:00
|
|
|
|
from ansible.errors import AnsibleError
|
2016-10-15 22:57:21 +02:00
|
|
|
|
from ansible.module_utils._text import to_bytes
|
2016-06-10 17:37:58 +02:00
|
|
|
|
from ansible.playbook.attribute import FieldAttribute
|
2015-07-21 18:12:22 +02:00
|
|
|
|
from ansible.playbook.base import Base
|
2016-11-22 21:50:24 +01:00
|
|
|
|
|
|
|
|
|
boolean = C.mk_boolean
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
__all__ = ['PlayContext']
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-09-30 15:27:29 +02:00
|
|
|
|
try:
|
|
|
|
|
from __main__ import display
|
|
|
|
|
except ImportError:
|
|
|
|
|
from ansible.utils.display import Display
|
|
|
|
|
display = Display()
|
|
|
|
|
|
2015-05-11 18:22:41 +02:00
|
|
|
|
# the magic variable mapping dictionary below is used to translate
|
2015-07-21 18:12:22 +02:00
|
|
|
|
# host/inventory variables to fields in the PlayContext
|
2015-05-11 18:22:41 +02:00
|
|
|
|
# object. The dictionary values are tuples, to account for aliases
|
|
|
|
|
# in variable names.
|
|
|
|
|
|
|
|
|
|
MAGIC_VARIABLE_MAPPING = dict(
|
|
|
|
|
connection = ('ansible_connection',),
|
|
|
|
|
remote_addr = ('ansible_ssh_host', 'ansible_host'),
|
|
|
|
|
remote_user = ('ansible_ssh_user', 'ansible_user'),
|
|
|
|
|
port = ('ansible_ssh_port', 'ansible_port'),
|
2016-09-07 23:13:11 +02:00
|
|
|
|
ssh_executable = ('ansible_ssh_executable',),
|
2015-10-02 06:35:22 +02:00
|
|
|
|
accelerate_port = ('ansible_accelerate_port',),
|
2015-05-11 18:22:41 +02:00
|
|
|
|
password = ('ansible_ssh_pass', 'ansible_password'),
|
|
|
|
|
private_key_file = ('ansible_ssh_private_key_file', 'ansible_private_key_file'),
|
2015-09-22 15:17:40 +02:00
|
|
|
|
pipelining = ('ansible_ssh_pipelining', 'ansible_pipelining'),
|
2015-05-11 18:22:41 +02:00
|
|
|
|
shell = ('ansible_shell_type',),
|
2016-11-28 18:49:40 +01:00
|
|
|
|
network_os = ('ansible_network_os',),
|
2015-06-15 05:19:49 +02:00
|
|
|
|
become = ('ansible_become',),
|
|
|
|
|
become_method = ('ansible_become_method',),
|
|
|
|
|
become_user = ('ansible_become_user',),
|
|
|
|
|
become_pass = ('ansible_become_password','ansible_become_pass'),
|
|
|
|
|
become_exe = ('ansible_become_exe',),
|
|
|
|
|
become_flags = ('ansible_become_flags',),
|
2015-10-02 09:25:48 +02:00
|
|
|
|
ssh_common_args = ('ansible_ssh_common_args',),
|
2016-03-24 22:09:41 +01:00
|
|
|
|
docker_extra_args= ('ansible_docker_extra_args',),
|
2015-10-02 09:25:48 +02:00
|
|
|
|
sftp_extra_args = ('ansible_sftp_extra_args',),
|
|
|
|
|
scp_extra_args = ('ansible_scp_extra_args',),
|
|
|
|
|
ssh_extra_args = ('ansible_ssh_extra_args',),
|
2015-06-15 05:19:49 +02:00
|
|
|
|
sudo = ('ansible_sudo',),
|
|
|
|
|
sudo_user = ('ansible_sudo_user',),
|
2015-07-06 19:48:52 +02:00
|
|
|
|
sudo_pass = ('ansible_sudo_password', 'ansible_sudo_pass'),
|
2015-06-15 05:19:49 +02:00
|
|
|
|
sudo_exe = ('ansible_sudo_exe',),
|
|
|
|
|
sudo_flags = ('ansible_sudo_flags',),
|
|
|
|
|
su = ('ansible_su',),
|
|
|
|
|
su_user = ('ansible_su_user',),
|
2015-07-06 19:48:52 +02:00
|
|
|
|
su_pass = ('ansible_su_password', 'ansible_su_pass'),
|
2015-06-15 05:19:49 +02:00
|
|
|
|
su_exe = ('ansible_su_exe',),
|
|
|
|
|
su_flags = ('ansible_su_flags',),
|
2016-03-18 14:40:04 +01:00
|
|
|
|
executable = ('ansible_shell_executable',),
|
2016-04-05 20:06:17 +02:00
|
|
|
|
module_compression = ('ansible_module_compression',),
|
2015-05-11 18:22:41 +02:00
|
|
|
|
)
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2016-10-15 22:57:21 +02:00
|
|
|
|
b_SU_PROMPT_LOCALIZATIONS = [
|
|
|
|
|
to_bytes('Password'),
|
|
|
|
|
to_bytes('암호'),
|
|
|
|
|
to_bytes('パスワード'),
|
|
|
|
|
to_bytes('Adgangskode'),
|
|
|
|
|
to_bytes('Contraseña'),
|
|
|
|
|
to_bytes('Contrasenya'),
|
|
|
|
|
to_bytes('Hasło'),
|
|
|
|
|
to_bytes('Heslo'),
|
|
|
|
|
to_bytes('Jelszó'),
|
|
|
|
|
to_bytes('Lösenord'),
|
|
|
|
|
to_bytes('Mật khẩu'),
|
|
|
|
|
to_bytes('Mot de passe'),
|
|
|
|
|
to_bytes('Parola'),
|
|
|
|
|
to_bytes('Parool'),
|
|
|
|
|
to_bytes('Pasahitza'),
|
|
|
|
|
to_bytes('Passord'),
|
|
|
|
|
to_bytes('Passwort'),
|
|
|
|
|
to_bytes('Salasana'),
|
|
|
|
|
to_bytes('Sandi'),
|
|
|
|
|
to_bytes('Senha'),
|
|
|
|
|
to_bytes('Wachtwoord'),
|
|
|
|
|
to_bytes('ססמה'),
|
|
|
|
|
to_bytes('Лозинка'),
|
|
|
|
|
to_bytes('Парола'),
|
|
|
|
|
to_bytes('Пароль'),
|
|
|
|
|
to_bytes('गुप्तशब्द'),
|
|
|
|
|
to_bytes('शब्दकूट'),
|
|
|
|
|
to_bytes('సంకేతపదము'),
|
|
|
|
|
to_bytes('හස්පදය'),
|
|
|
|
|
to_bytes('密码'),
|
|
|
|
|
to_bytes('密碼'),
|
2016-10-24 23:33:47 +02:00
|
|
|
|
to_bytes('口令'),
|
2015-06-15 04:35:53 +02:00
|
|
|
|
]
|
|
|
|
|
|
2015-07-31 23:51:26 +02:00
|
|
|
|
TASK_ATTRIBUTE_OVERRIDES = (
|
|
|
|
|
'become',
|
|
|
|
|
'become_user',
|
|
|
|
|
'become_pass',
|
|
|
|
|
'become_method',
|
2016-08-30 21:29:00 +02:00
|
|
|
|
'become_flags',
|
2015-07-31 23:51:26 +02:00
|
|
|
|
'connection',
|
2016-03-24 21:25:38 +01:00
|
|
|
|
'docker_extra_args',
|
2015-07-31 23:51:26 +02:00
|
|
|
|
'delegate_to',
|
|
|
|
|
'no_log',
|
|
|
|
|
'remote_user',
|
|
|
|
|
)
|
|
|
|
|
|
2015-12-28 18:25:27 +01:00
|
|
|
|
RESET_VARS = (
|
|
|
|
|
'ansible_connection',
|
2016-03-24 21:25:38 +01:00
|
|
|
|
'ansible_docker_extra_args',
|
2015-12-28 18:25:27 +01:00
|
|
|
|
'ansible_ssh_host',
|
|
|
|
|
'ansible_ssh_pass',
|
|
|
|
|
'ansible_ssh_port',
|
|
|
|
|
'ansible_ssh_user',
|
|
|
|
|
'ansible_ssh_private_key_file',
|
|
|
|
|
'ansible_ssh_pipelining',
|
2016-09-07 23:13:11 +02:00
|
|
|
|
'ansible_ssh_executable',
|
2015-12-28 18:25:27 +01:00
|
|
|
|
'ansible_user',
|
|
|
|
|
'ansible_host',
|
|
|
|
|
'ansible_port',
|
|
|
|
|
)
|
2015-07-31 23:51:26 +02:00
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
class PlayContext(Base):
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
|
|
|
|
'''
|
|
|
|
|
This class is used to consolidate the connection information for
|
|
|
|
|
hosts in a play and child tasks, where the task may override some
|
|
|
|
|
connection/authentication information.
|
|
|
|
|
'''
|
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
# connection fields, some are inherited from Base:
|
|
|
|
|
# (connection, port, remote_user, environment, no_log)
|
2016-03-24 21:25:38 +01:00
|
|
|
|
_docker_extra_args = FieldAttribute(isa='string')
|
2015-07-21 18:12:22 +02:00
|
|
|
|
_remote_addr = FieldAttribute(isa='string')
|
|
|
|
|
_password = FieldAttribute(isa='string')
|
|
|
|
|
_private_key_file = FieldAttribute(isa='string', default=C.DEFAULT_PRIVATE_KEY_FILE)
|
|
|
|
|
_timeout = FieldAttribute(isa='int', default=C.DEFAULT_TIMEOUT)
|
|
|
|
|
_shell = FieldAttribute(isa='string')
|
2016-11-28 18:49:40 +01:00
|
|
|
|
_network_os = FieldAttribute(isa='string')
|
2015-10-02 09:25:48 +02:00
|
|
|
|
_ssh_args = FieldAttribute(isa='string', default=C.ANSIBLE_SSH_ARGS)
|
Rework additional ssh argument handling
Now we have the following ways to set additional arguments:
1. [ssh_connection]ssh_args in ansible.cfg: global setting, prepended to
every command line for ssh/scp/sftp. Overrides default ControlPersist
settings.
2. ansible_ssh_common_args inventory variable. Appended to every command
line for ssh/scp/sftp. Used in addition to ssh_args, if set above, or
the default settings.
3. ansible_{sftp,scp,ssh}_extra_args inventory variables. Appended to
every command line for the relevant binary only. Used in addition to
#1 and #2, if set above, or the default settings.
3. Using the --ssh-common-args or --{sftp,scp,ssh}-extra-args command
line options (which are overriden by #2 and #3 above).
This preserves backwards compatibility (for ssh_args in ansible.cfg),
but also permits global settings (e.g. ProxyCommand via _common_args) or
ssh-specific options (e.g. -R via ssh_extra_args).
Fixes #12576
2015-10-02 08:27:47 +02:00
|
|
|
|
_ssh_common_args = FieldAttribute(isa='string')
|
|
|
|
|
_sftp_extra_args = FieldAttribute(isa='string')
|
|
|
|
|
_scp_extra_args = FieldAttribute(isa='string')
|
Squashed commit of the following:
commit 9921bb9d2002e136c030ff337c14f8b7eab0fc72
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Mon Aug 10 20:19:44 2015 +0530
Document --ssh-extra-args command-line option
commit 8b25595e7b1cc3658803d0821fbf498c18ee608a
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Thu Aug 13 13:24:57 2015 +0530
Don't disable GSSAPI/Pubkey authentication when using --ask-pass
This commit is based on a bug report and PR by kolbyjack (#6846) which
was subsequently closed and rebased as #11690. The original problem was:
«The password on the delegated host is different from the one I
provided on the command line, so it had to use the pubkey, and the
main host doesn't have a pubkey on it yet, so it had to use the
password.»
(This commit is revised and included here because #11690 would conflict
with the changes in #11908 otherwise.)
Closes #11690
commit 119d0323892c65e8169ae57e42bbe8e3517551a3
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Thu Aug 13 11:16:42 2015 +0530
Be more explicit about why SSH arguments are added
This adds vvvvv log messages that spell out in detail where each SSH
command-line argument is obtained from.
Unfortunately, we can't be sure if, say, self._play_context.remote_user
is obtained from ANSIBLE_REMOTE_USER in the environment, remote_user in
ansible.cfg, -u on the command line, or an ansible_ssh_user setting in
the inventory or on a task or play. In some cases, e.g. timeout, we
can't even be sure if it was set by the user or just a default.
Nevertheless, on the theory that at five v's you can use all the hints
available, I've mentioned the possible sources in the log messages.
Note that this caveat applies only to the arguments that ssh.py adds by
itself. In the case of ssh_args and ssh_extra_args, we know where they
are from, and say so, though we can't say WHERE in the inventory they
may be set (e.g. in host_vars or group_vars etc.).
commit b605c285baf505f75f0b7d73cb76b00d4723d02e
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Tue Aug 11 15:19:43 2015 +0530
Add a FAQ entry about ansible_ssh_extra_args
commit 49f8edd035cd28dd1cf8945f44ec3d55212910bd
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Mon Aug 10 20:48:50 2015 +0530
Allow ansible_ssh_args to be set as an inventory variable
Before this change, ssh_args could be set only in the [ssh_connection]
section of ansible.cfg, and was applied to all hosts. Now it's possible
to set ansible_ssh_args as an inventory variable (directly, or through
group_vars or host_vars) to selectively override the global setting.
Note that the default ControlPath settings are applied only if ssh_args
is not set, and this is true of ansible_ssh_args as well. So if you want
to override ssh_args but continue to set ControlPath, you'll need to
repeat the appropriate options when setting ansible_ssh_args.
(If you only need to add options to the default ssh_args, you may be
able to use the ansible_ssh_extra_args inventory variable instead.)
commit 37c1a5b6794cee29a7809ad056a86365a2c0f886
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Mon Aug 10 19:42:30 2015 +0530
Allow overriding ansible_ssh_extra_args on the command-line
This patch makes it possible to do:
ansible somehost -m setup \
--ssh-extra-args '-o ProxyCommand="ssh -W %h:%p -q user@bouncer.example.com"'
This overrides the inventory setting, if any, of ansible_ssh_extra_args.
Based on a patch originally by @Richard2ndQuadrant.
commit b023ace8a8a7ce6800e29129a27ebe8bf6bd38e0
Author: Abhijit Menon-Sen <ams@2ndQuadrant.com>
Date: Mon Aug 10 19:06:19 2015 +0530
Add an ansible_ssh_extra_args inventory variable
This can be used to configure a per-host or per-group ProxyCommand to
connect to hosts through a jumphost, e.g.:
inventory:
[gatewayed]
foo ansible_ssh_host=192.0.2.1
group_vars/gatewayed.yml:
ansible_ssh_extra_args: '-o ProxyCommand="ssh -W %h:%p -q bounceuser@gateway.example.com"'
Note that this variable is used in addition to any ssh_args configured
in the [ssh_connection] section of ansible.cfg (so you don't need to
repeat the ControlPath settings in ansible_ssh_extra_args).
2015-09-03 17:26:56 +02:00
|
|
|
|
_ssh_extra_args = FieldAttribute(isa='string')
|
2016-09-07 23:13:11 +02:00
|
|
|
|
_ssh_executable = FieldAttribute(isa='string', default=C.ANSIBLE_SSH_EXECUTABLE)
|
2015-09-03 07:07:29 +02:00
|
|
|
|
_connection_lockfd= FieldAttribute(isa='int')
|
2015-09-22 15:17:40 +02:00
|
|
|
|
_pipelining = FieldAttribute(isa='bool', default=C.ANSIBLE_SSH_PIPELINING)
|
2015-10-02 06:35:22 +02:00
|
|
|
|
_accelerate = FieldAttribute(isa='bool', default=False)
|
|
|
|
|
_accelerate_ipv6 = FieldAttribute(isa='bool', default=False, always_post_validate=True)
|
|
|
|
|
_accelerate_port = FieldAttribute(isa='int', default=C.ACCELERATE_PORT, always_post_validate=True)
|
2016-03-12 02:38:38 +01:00
|
|
|
|
_executable = FieldAttribute(isa='string', default=C.DEFAULT_EXECUTABLE)
|
2016-04-05 20:06:17 +02:00
|
|
|
|
_module_compression = FieldAttribute(isa='string', default=C.DEFAULT_MODULE_COMPRESSION)
|
2015-07-21 18:12:22 +02:00
|
|
|
|
|
|
|
|
|
# privilege escalation fields
|
|
|
|
|
_become = FieldAttribute(isa='bool')
|
|
|
|
|
_become_method = FieldAttribute(isa='string')
|
|
|
|
|
_become_user = FieldAttribute(isa='string')
|
|
|
|
|
_become_pass = FieldAttribute(isa='string')
|
|
|
|
|
_become_exe = FieldAttribute(isa='string')
|
|
|
|
|
_become_flags = FieldAttribute(isa='string')
|
|
|
|
|
_prompt = FieldAttribute(isa='string')
|
|
|
|
|
|
|
|
|
|
# backwards compatibility fields for sudo/su
|
|
|
|
|
_sudo_exe = FieldAttribute(isa='string')
|
|
|
|
|
_sudo_flags = FieldAttribute(isa='string')
|
|
|
|
|
_sudo_pass = FieldAttribute(isa='string')
|
|
|
|
|
_su_exe = FieldAttribute(isa='string')
|
|
|
|
|
_su_flags = FieldAttribute(isa='string')
|
|
|
|
|
_su_pass = FieldAttribute(isa='string')
|
|
|
|
|
|
|
|
|
|
# general flags
|
|
|
|
|
_verbosity = FieldAttribute(isa='int', default=0)
|
|
|
|
|
_only_tags = FieldAttribute(isa='set', default=set())
|
|
|
|
|
_skip_tags = FieldAttribute(isa='set', default=set())
|
|
|
|
|
_check_mode = FieldAttribute(isa='bool', default=False)
|
|
|
|
|
_force_handlers = FieldAttribute(isa='bool', default=False)
|
|
|
|
|
_start_at_task = FieldAttribute(isa='string')
|
|
|
|
|
_step = FieldAttribute(isa='bool', default=False)
|
2015-07-26 18:21:38 +02:00
|
|
|
|
_diff = FieldAttribute(isa='bool', default=False)
|
2015-07-21 18:12:22 +02:00
|
|
|
|
|
2015-09-03 06:45:42 +02:00
|
|
|
|
def __init__(self, play=None, options=None, passwords=None, connection_lockfd=None):
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
super(PlayContext, self).__init__()
|
|
|
|
|
|
2015-04-07 04:31:55 +02:00
|
|
|
|
if passwords is None:
|
|
|
|
|
passwords = {}
|
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
self.password = passwords.get('conn_pass','')
|
|
|
|
|
self.become_pass = passwords.get('become_pass','')
|
2015-01-28 15:55:18 +01:00
|
|
|
|
|
2015-09-06 15:00:39 +02:00
|
|
|
|
self.prompt = ''
|
|
|
|
|
self.success_key = ''
|
|
|
|
|
|
2015-09-03 07:07:29 +02:00
|
|
|
|
# a file descriptor to be used during locking operations
|
2015-09-03 06:45:42 +02:00
|
|
|
|
self.connection_lockfd = connection_lockfd
|
2015-09-03 06:18:52 +02:00
|
|
|
|
|
2015-04-07 04:31:55 +02:00
|
|
|
|
# set options before play to allow play to override them
|
|
|
|
|
if options:
|
|
|
|
|
self.set_options(options)
|
|
|
|
|
|
2015-04-28 20:26:05 +02:00
|
|
|
|
if play:
|
|
|
|
|
self.set_play(play)
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
|
|
|
|
def set_play(self, play):
|
|
|
|
|
'''
|
|
|
|
|
Configures this connection information instance with data from
|
|
|
|
|
the play class.
|
|
|
|
|
'''
|
|
|
|
|
|
2015-10-02 06:35:22 +02:00
|
|
|
|
# special handling for accelerated mode, as it is set in a separate
|
|
|
|
|
# play option from the connection parameter
|
|
|
|
|
self.accelerate = play.accelerate
|
|
|
|
|
self.accelerate_ipv6 = play.accelerate_ipv6
|
|
|
|
|
self.accelerate_port = play.accelerate_port
|
|
|
|
|
|
2014-11-14 23:14:08 +01:00
|
|
|
|
if play.connection:
|
|
|
|
|
self.connection = play.connection
|
|
|
|
|
|
2015-04-07 04:31:55 +02:00
|
|
|
|
if play.remote_user:
|
2015-07-10 07:53:59 +02:00
|
|
|
|
self.remote_user = play.remote_user
|
2015-04-07 04:31:55 +02:00
|
|
|
|
|
|
|
|
|
if play.port:
|
2015-07-10 07:53:59 +02:00
|
|
|
|
self.port = int(play.port)
|
2015-04-07 04:31:55 +02:00
|
|
|
|
|
|
|
|
|
if play.become is not None:
|
2015-07-10 07:53:59 +02:00
|
|
|
|
self.become = play.become
|
2015-04-07 04:31:55 +02:00
|
|
|
|
if play.become_method:
|
|
|
|
|
self.become_method = play.become_method
|
|
|
|
|
if play.become_user:
|
2015-07-10 07:53:59 +02:00
|
|
|
|
self.become_user = play.become_user
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-07-10 07:53:59 +02:00
|
|
|
|
if play.force_handlers is not None:
|
|
|
|
|
self.force_handlers = play.force_handlers
|
2015-01-09 18:39:49 +01:00
|
|
|
|
|
2014-11-14 23:14:08 +01:00
|
|
|
|
def set_options(self, options):
|
|
|
|
|
'''
|
|
|
|
|
Configures this connection information instance with data from
|
|
|
|
|
options specified by the user on the command line. These have a
|
2015-08-01 15:55:45 +02:00
|
|
|
|
lower precedence than those set on the play or host.
|
2014-11-14 23:14:08 +01:00
|
|
|
|
'''
|
|
|
|
|
|
2015-04-07 04:31:55 +02:00
|
|
|
|
# privilege escalation
|
|
|
|
|
self.become = options.become
|
|
|
|
|
self.become_method = options.become_method
|
|
|
|
|
self.become_user = options.become_user
|
|
|
|
|
|
2016-02-14 02:12:37 +01:00
|
|
|
|
self.check_mode = boolean(options.check)
|
|
|
|
|
|
|
|
|
|
# get ssh options FIXME: make these common to all connections
|
2016-03-24 21:25:38 +01:00
|
|
|
|
for flag in ['ssh_common_args', 'docker_extra_args', 'sftp_extra_args', 'scp_extra_args', 'ssh_extra_args']:
|
2016-02-14 02:12:37 +01:00
|
|
|
|
setattr(self, flag, getattr(options,flag, ''))
|
|
|
|
|
|
2015-04-07 04:31:55 +02:00
|
|
|
|
# general flags (should we move out?)
|
2016-02-14 02:12:37 +01:00
|
|
|
|
for flag in ['connection','remote_user', 'private_key_file', 'verbosity', 'force_handlers', 'step', 'start_at_task', 'diff']:
|
|
|
|
|
attribute = getattr(options, flag, False)
|
|
|
|
|
if attribute:
|
|
|
|
|
setattr(self, flag, attribute)
|
|
|
|
|
|
2015-09-16 05:26:21 +02:00
|
|
|
|
if hasattr(options, 'timeout') and options.timeout:
|
|
|
|
|
self.timeout = int(options.timeout)
|
2015-01-28 15:55:18 +01:00
|
|
|
|
|
2016-09-29 23:14:02 +02:00
|
|
|
|
# get the tag info from options. We check to see if the options have
|
|
|
|
|
# the attribute, as it is not always added via the CLI
|
2015-01-02 14:51:15 +01:00
|
|
|
|
if hasattr(options, 'tags'):
|
2016-09-29 23:14:02 +02:00
|
|
|
|
self.only_tags.update(options.tags)
|
2015-01-02 14:51:15 +01:00
|
|
|
|
|
2015-01-12 23:04:56 +01:00
|
|
|
|
if len(self.only_tags) == 0:
|
|
|
|
|
self.only_tags = set(['all'])
|
|
|
|
|
|
2015-01-02 14:51:15 +01:00
|
|
|
|
if hasattr(options, 'skip_tags'):
|
2016-09-29 23:14:02 +02:00
|
|
|
|
self.skip_tags.update(options.skip_tags)
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-09-25 07:33:45 +02:00
|
|
|
|
def set_task_and_variable_override(self, task, variables, templar):
|
2014-11-14 23:14:08 +01:00
|
|
|
|
'''
|
|
|
|
|
Sets attributes from the task if they are set, which will override
|
|
|
|
|
those from the play.
|
|
|
|
|
'''
|
|
|
|
|
|
2015-07-21 18:12:22 +02:00
|
|
|
|
new_info = self.copy()
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-05-11 18:22:41 +02:00
|
|
|
|
# loop through a subset of attributes on the task object and set
|
|
|
|
|
# connection fields based on their values
|
2015-07-31 23:51:26 +02:00
|
|
|
|
for attr in TASK_ATTRIBUTE_OVERRIDES:
|
2014-11-14 23:14:08 +01:00
|
|
|
|
if hasattr(task, attr):
|
|
|
|
|
attr_val = getattr(task, attr)
|
2015-05-22 10:32:40 +02:00
|
|
|
|
if attr_val is not None:
|
2015-03-20 20:13:51 +01:00
|
|
|
|
setattr(new_info, attr, attr_val)
|
2014-11-14 23:14:08 +01:00
|
|
|
|
|
2015-09-14 18:02:45 +02:00
|
|
|
|
# next, use the MAGIC_VARIABLE_MAPPING dictionary to update this
|
2015-09-18 20:48:26 +02:00
|
|
|
|
# connection info object with 'magic' variables from the variable list.
|
|
|
|
|
# If the value 'ansible_delegated_vars' is in the variables, it means
|
|
|
|
|
# we have a delegated-to host, so we check there first before looking
|
|
|
|
|
# at the variables in general
|
2015-09-25 07:33:45 +02:00
|
|
|
|
if task.delegate_to is not None:
|
|
|
|
|
# In the case of a loop, the delegated_to host may have been
|
|
|
|
|
# templated based on the loop variable, so we try and locate
|
|
|
|
|
# the host name in the delegated variable dictionary here
|
|
|
|
|
delegated_host_name = templar.template(task.delegate_to)
|
|
|
|
|
delegated_vars = variables.get('ansible_delegated_vars', dict()).get(delegated_host_name, dict())
|
2015-11-30 20:39:49 +01:00
|
|
|
|
|
|
|
|
|
delegated_transport = C.DEFAULT_TRANSPORT
|
|
|
|
|
for transport_var in MAGIC_VARIABLE_MAPPING.get('connection'):
|
|
|
|
|
if transport_var in delegated_vars:
|
|
|
|
|
delegated_transport = delegated_vars[transport_var]
|
|
|
|
|
break
|
|
|
|
|
|
2015-09-30 15:27:29 +02:00
|
|
|
|
# make sure this delegated_to host has something set for its remote
|
|
|
|
|
# address, otherwise we default to connecting to it by name. This
|
|
|
|
|
# may happen when users put an IP entry into their inventory, or if
|
|
|
|
|
# they rely on DNS for a non-inventory hostname
|
|
|
|
|
for address_var in MAGIC_VARIABLE_MAPPING.get('remote_addr'):
|
|
|
|
|
if address_var in delegated_vars:
|
|
|
|
|
break
|
|
|
|
|
else:
|
2015-10-18 17:00:20 +02:00
|
|
|
|
display.debug("no remote address found for delegated host %s\nusing its name, so success depends on DNS resolution" % delegated_host_name)
|
2015-09-30 15:27:29 +02:00
|
|
|
|
delegated_vars['ansible_host'] = delegated_host_name
|
2015-11-30 20:39:49 +01:00
|
|
|
|
|
2015-11-30 22:14:40 +01:00
|
|
|
|
# reset the port back to the default if none was specified, to prevent
|
|
|
|
|
# the delegated host from inheriting the original host's setting
|
2015-11-30 20:39:49 +01:00
|
|
|
|
for port_var in MAGIC_VARIABLE_MAPPING.get('port'):
|
|
|
|
|
if port_var in delegated_vars:
|
|
|
|
|
break
|
|
|
|
|
else:
|
|
|
|
|
if delegated_transport == 'winrm':
|
|
|
|
|
delegated_vars['ansible_port'] = 5986
|
|
|
|
|
else:
|
|
|
|
|
delegated_vars['ansible_port'] = C.DEFAULT_REMOTE_PORT
|
2015-11-30 22:14:40 +01:00
|
|
|
|
|
|
|
|
|
# and likewise for the remote user
|
|
|
|
|
for user_var in MAGIC_VARIABLE_MAPPING.get('remote_user'):
|
2016-06-07 15:36:17 +02:00
|
|
|
|
if user_var in delegated_vars and delegated_vars[user_var]:
|
2015-11-30 22:14:40 +01:00
|
|
|
|
break
|
|
|
|
|
else:
|
2015-12-03 17:29:09 +01:00
|
|
|
|
delegated_vars['ansible_user'] = task.remote_user or self.remote_user
|
2015-09-25 07:33:45 +02:00
|
|
|
|
else:
|
|
|
|
|
delegated_vars = dict()
|
|
|
|
|
|
2016-03-12 02:38:38 +01:00
|
|
|
|
# setup shell
|
|
|
|
|
for exe_var in MAGIC_VARIABLE_MAPPING.get('executable'):
|
|
|
|
|
if exe_var in variables:
|
|
|
|
|
setattr(new_info, 'executable', variables.get(exe_var))
|
|
|
|
|
|
2016-01-18 23:32:25 +01:00
|
|
|
|
attrs_considered = []
|
2015-09-03 08:23:27 +02:00
|
|
|
|
for (attr, variable_names) in iteritems(MAGIC_VARIABLE_MAPPING):
|
2015-05-11 18:22:41 +02:00
|
|
|
|
for variable_name in variable_names:
|
2016-01-18 23:32:25 +01:00
|
|
|
|
if attr in attrs_considered:
|
|
|
|
|
continue
|
2016-03-17 16:50:18 +01:00
|
|
|
|
# if delegation task ONLY use delegated host vars, avoid delegated FOR host vars
|
|
|
|
|
if task.delegate_to is not None:
|
|
|
|
|
if isinstance(delegated_vars, dict) and variable_name in delegated_vars:
|
|
|
|
|
setattr(new_info, attr, delegated_vars[variable_name])
|
|
|
|
|
attrs_considered.append(attr)
|
2015-09-18 20:48:26 +02:00
|
|
|
|
elif variable_name in variables:
|
2015-05-11 18:22:41 +02:00
|
|
|
|
setattr(new_info, attr, variables[variable_name])
|
2016-01-18 23:32:25 +01:00
|
|
|
|
attrs_considered.append(attr)
|
2016-03-17 16:50:18 +01:00
|
|
|
|
# no else, as no other vars should be considered
|
2015-05-11 18:22:41 +02:00
|
|
|
|
|
2016-03-20 18:33:51 +01:00
|
|
|
|
# become legacy updates -- from commandline
|
2015-07-07 05:24:00 +02:00
|
|
|
|
if not new_info.become_pass:
|
|
|
|
|
if new_info.become_method == 'sudo' and new_info.sudo_pass:
|
|
|
|
|
setattr(new_info, 'become_pass', new_info.sudo_pass)
|
|
|
|
|
elif new_info.become_method == 'su' and new_info.su_pass:
|
|
|
|
|
setattr(new_info, 'become_pass', new_info.su_pass)
|
|
|
|
|
|
2016-03-20 18:33:51 +01:00
|
|
|
|
# become legacy updates -- from inventory file (inventory overrides
|
|
|
|
|
# commandline)
|
|
|
|
|
for become_pass_name in MAGIC_VARIABLE_MAPPING.get('become_pass'):
|
|
|
|
|
if become_pass_name in variables:
|
|
|
|
|
break
|
|
|
|
|
else: # This is a for-else
|
|
|
|
|
if new_info.become_method == 'sudo':
|
|
|
|
|
for sudo_pass_name in MAGIC_VARIABLE_MAPPING.get('sudo_pass'):
|
|
|
|
|
if sudo_pass_name in variables:
|
|
|
|
|
setattr(new_info, 'become_pass', variables[sudo_pass_name])
|
|
|
|
|
break
|
|
|
|
|
if new_info.become_method == 'sudo':
|
|
|
|
|
for su_pass_name in MAGIC_VARIABLE_MAPPING.get('su_pass'):
|
|
|
|
|
if su_pass_name in variables:
|
|
|
|
|
setattr(new_info, 'become_pass', variables[su_pass_name])
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
# make sure we get port defaults if needed
|
|
|
|
|
if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None:
|
|
|
|
|
new_info.port = int(C.DEFAULT_REMOTE_PORT)
|
|
|
|
|
|
2015-10-05 22:29:43 +02:00
|
|
|
|
# special overrides for the connection setting
|
|
|
|
|
if len(delegated_vars) > 0:
|
|
|
|
|
# in the event that we were using local before make sure to reset the
|
|
|
|
|
# connection type to the default transport for the delegated-to host,
|
|
|
|
|
# if not otherwise specified
|
|
|
|
|
for connection_type in MAGIC_VARIABLE_MAPPING.get('connection'):
|
|
|
|
|
if connection_type in delegated_vars:
|
|
|
|
|
break
|
|
|
|
|
else:
|
2015-10-20 20:02:39 +02:00
|
|
|
|
remote_addr_local = new_info.remote_addr in C.LOCALHOST
|
|
|
|
|
inv_hostname_local = delegated_vars.get('inventory_hostname') in C.LOCALHOST
|
|
|
|
|
if remote_addr_local and inv_hostname_local:
|
2015-10-07 02:37:31 +02:00
|
|
|
|
setattr(new_info, 'connection', 'local')
|
2015-10-20 20:02:39 +02:00
|
|
|
|
elif getattr(new_info, 'connection', None) == 'local' and (not remote_addr_local or not inv_hostname_local):
|
2015-10-05 22:29:43 +02:00
|
|
|
|
setattr(new_info, 'connection', C.DEFAULT_TRANSPORT)
|
2015-09-14 18:02:45 +02:00
|
|
|
|
|
2016-09-29 00:33:40 +02:00
|
|
|
|
# if the final connection type is local, reset the remote_user value
|
|
|
|
|
# to that of the currently logged in user, to ensure any become settings
|
|
|
|
|
# are obeyed correctly
|
|
|
|
|
# additionally, we need to do this check after final connection has been
|
|
|
|
|
# correctly set above ...
|
|
|
|
|
if new_info.connection == 'local':
|
|
|
|
|
new_info.remote_user = pwd.getpwuid(os.getuid()).pw_name
|
|
|
|
|
|
2015-09-26 05:57:03 +02:00
|
|
|
|
# set no_log to default if it was not previouslly set
|
|
|
|
|
if new_info.no_log is None:
|
|
|
|
|
new_info.no_log = C.DEFAULT_NO_LOG
|
|
|
|
|
|
2015-12-05 21:59:51 +01:00
|
|
|
|
# set become defaults if not previouslly set
|
|
|
|
|
task.set_become_defaults(new_info.become, new_info.become_method, new_info.become_user)
|
|
|
|
|
|
2015-12-08 18:20:49 +01:00
|
|
|
|
if task.always_run:
|
2016-07-23 02:40:14 +02:00
|
|
|
|
display.deprecated("always_run is deprecated. Use check_mode = no instead.", version="2.4", removed=False)
|
2015-12-08 18:20:49 +01:00
|
|
|
|
new_info.check_mode = False
|
|
|
|
|
|
2016-07-23 02:40:14 +02:00
|
|
|
|
# check_mode replaces always_run, overwrite always_run if both are given
|
|
|
|
|
if task.check_mode is not None:
|
|
|
|
|
new_info.check_mode = task.check_mode
|
|
|
|
|
|
|
|
|
|
|
2014-11-14 23:14:08 +01:00
|
|
|
|
return new_info
|
|
|
|
|
|
2015-06-24 18:12:54 +02:00
|
|
|
|
def make_become_cmd(self, cmd, executable=None):
|
2015-06-15 04:35:53 +02:00
|
|
|
|
""" helper function to create privilege escalation commands """
|
2015-03-13 17:57:27 +01:00
|
|
|
|
|
|
|
|
|
prompt = None
|
2015-06-15 04:35:53 +02:00
|
|
|
|
success_key = None
|
2015-09-04 15:30:31 +02:00
|
|
|
|
self.prompt = None
|
2015-03-13 17:57:27 +01:00
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
if self.become:
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2016-06-15 17:23:14 +02:00
|
|
|
|
if not executable:
|
2016-06-10 17:37:58 +02:00
|
|
|
|
executable = self.executable
|
|
|
|
|
|
2015-06-15 04:35:53 +02:00
|
|
|
|
becomecmd = None
|
2015-09-18 07:52:26 +02:00
|
|
|
|
randbits = ''.join(random.choice(string.ascii_lowercase) for x in range(32))
|
2015-06-15 04:35:53 +02:00
|
|
|
|
success_key = 'BECOME-SUCCESS-%s' % randbits
|
2016-11-17 22:18:29 +01:00
|
|
|
|
success_cmd = shlex_quote('echo %s; %s' % (success_key, cmd))
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2016-06-10 17:37:58 +02:00
|
|
|
|
if executable:
|
|
|
|
|
command = '%s -c %s' % (executable, success_cmd)
|
|
|
|
|
else:
|
|
|
|
|
command = success_cmd
|
|
|
|
|
|
2015-09-02 15:29:34 +02:00
|
|
|
|
# set executable to use for the privilege escalation method, with various overrides
|
|
|
|
|
exe = self.become_exe or \
|
|
|
|
|
getattr(self, '%s_exe' % self.become_method, None) or \
|
2015-09-02 15:52:26 +02:00
|
|
|
|
C.DEFAULT_BECOME_EXE or \
|
2015-09-02 15:29:34 +02:00
|
|
|
|
getattr(C, 'DEFAULT_%s_EXE' % self.become_method.upper(), None) or \
|
|
|
|
|
self.become_method
|
|
|
|
|
|
2015-09-02 17:31:39 +02:00
|
|
|
|
# set flags to use for the privilege escalation method, with various overrides
|
|
|
|
|
flags = self.become_flags or \
|
|
|
|
|
getattr(self, '%s_flags' % self.become_method, None) or \
|
|
|
|
|
C.DEFAULT_BECOME_FLAGS or \
|
|
|
|
|
getattr(C, 'DEFAULT_%s_FLAGS' % self.become_method.upper(), None) or \
|
|
|
|
|
''
|
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
if self.become_method == 'sudo':
|
2015-09-26 13:58:22 +02:00
|
|
|
|
# If we have a password, we run sudo with a randomly-generated
|
2016-01-27 20:09:14 +01:00
|
|
|
|
# prompt set using -p. Otherwise we run it with default -n, which makes
|
2015-09-26 13:58:22 +02:00
|
|
|
|
# it fail if it would have prompted for a password.
|
2016-01-27 20:09:14 +01:00
|
|
|
|
# Cannot rely on -n as it can be removed from defaults, which should be
|
|
|
|
|
# done for older versions of sudo that do not support the option.
|
2015-09-26 13:58:22 +02:00
|
|
|
|
#
|
|
|
|
|
# Passing a quoted compound command to sudo (or sudo -s)
|
2016-11-17 22:18:29 +01:00
|
|
|
|
# directly doesn't work, so we shellquote it with shlex_quote()
|
2015-09-26 13:58:22 +02:00
|
|
|
|
# and pass the quoted string to the user's shell.
|
2015-08-15 18:05:39 +02:00
|
|
|
|
|
|
|
|
|
# force quick error if password is required but not supplied, should prevent sudo hangs.
|
2015-09-04 15:30:31 +02:00
|
|
|
|
if self.become_pass:
|
|
|
|
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
2016-06-10 17:37:58 +02:00
|
|
|
|
becomecmd = '%s %s -p "%s" -u %s %s' % (exe, flags.replace('-n',''), prompt, self.become_user, command)
|
2015-09-04 15:30:31 +02:00
|
|
|
|
else:
|
2016-06-10 17:37:58 +02:00
|
|
|
|
becomecmd = '%s %s -u %s %s' % (exe, flags, self.become_user, command)
|
2015-08-15 18:05:39 +02:00
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
|
|
|
|
elif self.become_method == 'su':
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2016-01-27 20:09:14 +01:00
|
|
|
|
# passing code ref to examine prompt as simple string comparisson isn't good enough with su
|
2016-10-15 22:57:21 +02:00
|
|
|
|
def detect_su_prompt(b_data):
|
2016-10-24 23:33:47 +02:00
|
|
|
|
b_password_string = b"|".join([b'(\w+\'s )?' + x for x in b_SU_PROMPT_LOCALIZATIONS])
|
|
|
|
|
# Colon or unicode fullwidth colon
|
|
|
|
|
b_password_string = b_password_string + to_bytes(u' ?(:|:) ?')
|
|
|
|
|
b_SU_PROMPT_LOCALIZATIONS_RE = re.compile(b_password_string, flags=re.IGNORECASE)
|
2016-10-15 22:57:21 +02:00
|
|
|
|
return bool(b_SU_PROMPT_LOCALIZATIONS_RE.match(b_data))
|
2015-06-15 07:07:02 +02:00
|
|
|
|
prompt = detect_su_prompt
|
2016-01-27 20:09:14 +01:00
|
|
|
|
|
2016-11-17 22:18:29 +01:00
|
|
|
|
becomecmd = '%s %s %s -c %s' % (exe, flags, self.become_user, shlex_quote(command))
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
|
|
|
|
elif self.become_method == 'pbrun':
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2016-10-17 19:01:34 +02:00
|
|
|
|
prompt='Password:'
|
|
|
|
|
becomecmd = '%s %s -u %s %s' % (exe, flags, self.become_user, success_cmd)
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
2016-09-01 22:54:31 +02:00
|
|
|
|
elif self.become_method == 'ksu':
|
2016-10-15 22:57:21 +02:00
|
|
|
|
def detect_ksu_prompt(b_data):
|
|
|
|
|
return re.match(b"Kerberos password for .*@.*:", b_data)
|
2016-09-01 22:54:31 +02:00
|
|
|
|
|
|
|
|
|
prompt = detect_ksu_prompt
|
|
|
|
|
becomecmd = '%s %s %s -e %s' % (exe, self.become_user, flags, command)
|
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
elif self.become_method == 'pfexec':
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
# No user as it uses it's own exec_attr to figure it out
|
2015-03-20 20:13:51 +01:00
|
|
|
|
becomecmd = '%s %s "%s"' % (exe, flags, success_cmd)
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
2015-08-16 00:48:23 +02:00
|
|
|
|
elif self.become_method == 'runas':
|
|
|
|
|
raise AnsibleError("'runas' is not yet implemented")
|
2016-02-10 01:05:41 +01:00
|
|
|
|
#FIXME: figure out prompt
|
2015-08-16 00:48:23 +02:00
|
|
|
|
# this is not for use with winrm plugin but if they ever get ssh native on windoez
|
|
|
|
|
becomecmd = '%s %s /user:%s "%s"' % (exe, flags, self.become_user, success_cmd)
|
|
|
|
|
|
2015-08-18 03:31:18 +02:00
|
|
|
|
elif self.become_method == 'doas':
|
|
|
|
|
|
2016-09-13 22:17:24 +02:00
|
|
|
|
prompt = 'doas (%s@' % self.remote_user
|
2015-08-18 03:31:18 +02:00
|
|
|
|
exe = self.become_exe or 'doas'
|
|
|
|
|
|
|
|
|
|
if not self.become_pass:
|
|
|
|
|
flags += ' -n '
|
|
|
|
|
|
|
|
|
|
if self.become_user:
|
|
|
|
|
flags += ' -u %s ' % self.become_user
|
|
|
|
|
|
2016-02-10 01:05:41 +01:00
|
|
|
|
#FIXME: make shell independant
|
2015-08-18 03:31:18 +02:00
|
|
|
|
becomecmd = '%s %s echo %s && %s %s env ANSIBLE=true %s' % (exe, flags, success_key, exe, flags, cmd)
|
|
|
|
|
|
2016-04-25 17:24:26 +02:00
|
|
|
|
elif self.become_method == 'dzdo':
|
|
|
|
|
|
|
|
|
|
exe = self.become_exe or 'dzdo'
|
2016-09-30 22:07:48 +02:00
|
|
|
|
if self.become_pass:
|
|
|
|
|
prompt = '[dzdo via ansible, key=%s] password: ' % randbits
|
2016-11-17 22:18:29 +01:00
|
|
|
|
becomecmd = '%s -p %s -u %s %s' % (exe, shlex_quote(prompt), self.become_user, command)
|
2016-09-30 22:07:48 +02:00
|
|
|
|
else:
|
|
|
|
|
becomecmd = '%s -u %s %s' % (exe, self.become_user, command)
|
2016-04-25 17:24:26 +02:00
|
|
|
|
|
2015-03-13 21:31:20 +01:00
|
|
|
|
else:
|
2015-04-15 01:04:08 +02:00
|
|
|
|
raise AnsibleError("Privilege escalation method not found: %s" % self.become_method)
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
2015-09-04 15:30:31 +02:00
|
|
|
|
if self.become_pass:
|
|
|
|
|
self.prompt = prompt
|
2015-06-24 18:12:54 +02:00
|
|
|
|
self.success_key = success_key
|
2016-02-10 01:05:41 +01:00
|
|
|
|
return becomecmd
|
2015-03-13 21:31:20 +01:00
|
|
|
|
|
2015-07-13 22:46:51 +02:00
|
|
|
|
return cmd
|
2015-06-15 04:35:53 +02:00
|
|
|
|
|
2015-04-15 04:10:17 +02:00
|
|
|
|
def update_vars(self, variables):
|
|
|
|
|
'''
|
|
|
|
|
Adds 'magic' variables relating to connections to the variable dictionary provided.
|
2015-06-15 07:02:27 +02:00
|
|
|
|
In case users need to access from the play, this is a legacy from runner.
|
2015-04-15 04:10:17 +02:00
|
|
|
|
'''
|
2015-06-15 07:02:27 +02:00
|
|
|
|
|
2016-02-04 23:15:54 +01:00
|
|
|
|
for prop, var_list in MAGIC_VARIABLE_MAPPING.items():
|
2016-02-22 23:09:58 +01:00
|
|
|
|
try:
|
|
|
|
|
if 'become' in prop:
|
|
|
|
|
continue
|
|
|
|
|
|
|
|
|
|
var_val = getattr(self, prop)
|
2016-02-04 23:15:54 +01:00
|
|
|
|
for var_opt in var_list:
|
2016-02-23 21:07:51 +01:00
|
|
|
|
if var_opt not in variables and var_val is not None:
|
2016-02-04 23:15:54 +01:00
|
|
|
|
variables[var_opt] = var_val
|
2016-02-22 23:09:58 +01:00
|
|
|
|
except AttributeError:
|
|
|
|
|
continue
|