2015-06-15 02:35:53 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
2014-11-14 22:14:08 +00: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
|
|
|
|
|
|
|
|
import pipes
|
|
|
|
import random
|
2015-06-15 02:35:53 +00:00
|
|
|
import re
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
from ansible import constants as C
|
2015-07-21 16:12:22 +00:00
|
|
|
from ansible.errors import AnsibleError
|
|
|
|
from ansible.playbook.attribute import Attribute, FieldAttribute
|
|
|
|
from ansible.playbook.base import Base
|
2015-01-20 20:03:26 +00:00
|
|
|
from ansible.template import Templar
|
2015-01-28 14:55:18 +00:00
|
|
|
from ansible.utils.boolean import boolean
|
2015-07-22 11:45:03 +00:00
|
|
|
from ansible.utils.unicode import to_unicode
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-07-21 16:12:22 +00:00
|
|
|
__all__ = ['PlayContext']
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-06-15 02:35:53 +00:00
|
|
|
SU_PROMPT_LOCALIZATIONS = [
|
|
|
|
'Password',
|
|
|
|
'암호',
|
|
|
|
'パスワード',
|
|
|
|
'Adgangskode',
|
|
|
|
'Contraseña',
|
|
|
|
'Contrasenya',
|
|
|
|
'Hasło',
|
|
|
|
'Heslo',
|
|
|
|
'Jelszó',
|
|
|
|
'Lösenord',
|
|
|
|
'Mật khẩu',
|
|
|
|
'Mot de passe',
|
|
|
|
'Parola',
|
|
|
|
'Parool',
|
|
|
|
'Pasahitza',
|
|
|
|
'Passord',
|
|
|
|
'Passwort',
|
|
|
|
'Salasana',
|
|
|
|
'Sandi',
|
|
|
|
'Senha',
|
|
|
|
'Wachtwoord',
|
|
|
|
'ססמה',
|
|
|
|
'Лозинка',
|
|
|
|
'Парола',
|
|
|
|
'Пароль',
|
|
|
|
'गुप्तशब्द',
|
|
|
|
'शब्दकूट',
|
|
|
|
'సంకేతపదము',
|
|
|
|
'හස්පදය',
|
|
|
|
'密码',
|
|
|
|
'密碼',
|
|
|
|
]
|
|
|
|
|
2015-05-11 16:22:41 +00:00
|
|
|
# the magic variable mapping dictionary below is used to translate
|
2015-07-21 16:12:22 +00:00
|
|
|
# host/inventory variables to fields in the PlayContext
|
2015-05-11 16:22:41 +00: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'),
|
|
|
|
password = ('ansible_ssh_pass', 'ansible_password'),
|
|
|
|
private_key_file = ('ansible_ssh_private_key_file', 'ansible_private_key_file'),
|
|
|
|
shell = ('ansible_shell_type',),
|
2015-06-15 03:19:49 +00: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',),
|
|
|
|
sudo = ('ansible_sudo',),
|
|
|
|
sudo_user = ('ansible_sudo_user',),
|
2015-07-06 17:48:52 +00:00
|
|
|
sudo_pass = ('ansible_sudo_password', 'ansible_sudo_pass'),
|
2015-06-15 03:19:49 +00:00
|
|
|
sudo_exe = ('ansible_sudo_exe',),
|
|
|
|
sudo_flags = ('ansible_sudo_flags',),
|
|
|
|
su = ('ansible_su',),
|
|
|
|
su_user = ('ansible_su_user',),
|
2015-07-06 17:48:52 +00:00
|
|
|
su_pass = ('ansible_su_password', 'ansible_su_pass'),
|
2015-06-15 03:19:49 +00:00
|
|
|
su_exe = ('ansible_su_exe',),
|
|
|
|
su_flags = ('ansible_su_flags',),
|
2015-05-11 16:22:41 +00:00
|
|
|
)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-06-15 02:35:53 +00:00
|
|
|
SU_PROMPT_LOCALIZATIONS = [
|
|
|
|
'Password',
|
|
|
|
'암호',
|
|
|
|
'パスワード',
|
|
|
|
'Adgangskode',
|
|
|
|
'Contraseña',
|
|
|
|
'Contrasenya',
|
|
|
|
'Hasło',
|
|
|
|
'Heslo',
|
|
|
|
'Jelszó',
|
|
|
|
'Lösenord',
|
|
|
|
'Mật khẩu',
|
|
|
|
'Mot de passe',
|
|
|
|
'Parola',
|
|
|
|
'Parool',
|
|
|
|
'Pasahitza',
|
|
|
|
'Passord',
|
|
|
|
'Passwort',
|
|
|
|
'Salasana',
|
|
|
|
'Sandi',
|
|
|
|
'Senha',
|
|
|
|
'Wachtwoord',
|
|
|
|
'ססמה',
|
|
|
|
'Лозинка',
|
|
|
|
'Парола',
|
|
|
|
'Пароль',
|
|
|
|
'गुप्तशब्द',
|
|
|
|
'शब्दकूट',
|
|
|
|
'సంకేతపదము',
|
|
|
|
'හස්පදය',
|
|
|
|
'密码',
|
|
|
|
'密碼',
|
|
|
|
]
|
|
|
|
|
2015-07-31 21:51:26 +00:00
|
|
|
TASK_ATTRIBUTE_OVERRIDES = (
|
|
|
|
'become',
|
|
|
|
'become_user',
|
|
|
|
'become_pass',
|
|
|
|
'become_method',
|
|
|
|
'connection',
|
|
|
|
'delegate_to',
|
|
|
|
'no_log',
|
|
|
|
'remote_user',
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2015-07-21 16:12:22 +00:00
|
|
|
class PlayContext(Base):
|
2014-11-14 22:14:08 +00: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 16:12:22 +00:00
|
|
|
# connection fields, some are inherited from Base:
|
|
|
|
# (connection, port, remote_user, environment, no_log)
|
|
|
|
_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')
|
|
|
|
|
|
|
|
# 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 16:21:38 +00:00
|
|
|
_diff = FieldAttribute(isa='bool', default=False)
|
2015-07-21 16:12:22 +00:00
|
|
|
|
2015-04-07 02:31:55 +00:00
|
|
|
def __init__(self, play=None, options=None, passwords=None):
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-07-21 16:12:22 +00:00
|
|
|
super(PlayContext, self).__init__()
|
|
|
|
|
2015-04-07 02:31:55 +00:00
|
|
|
if passwords is None:
|
|
|
|
passwords = {}
|
|
|
|
|
2015-07-21 16:12:22 +00:00
|
|
|
self.password = passwords.get('conn_pass','')
|
|
|
|
self.become_pass = passwords.get('become_pass','')
|
2015-01-28 14:55:18 +00:00
|
|
|
|
2015-04-07 02:31:55 +00:00
|
|
|
# set options before play to allow play to override them
|
|
|
|
if options:
|
|
|
|
self.set_options(options)
|
|
|
|
|
2015-04-28 18:26:05 +00:00
|
|
|
if play:
|
|
|
|
self.set_play(play)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
def set_play(self, play):
|
|
|
|
'''
|
|
|
|
Configures this connection information instance with data from
|
|
|
|
the play class.
|
|
|
|
'''
|
|
|
|
|
|
|
|
if play.connection:
|
|
|
|
self.connection = play.connection
|
|
|
|
|
2015-04-07 02:31:55 +00:00
|
|
|
if play.remote_user:
|
2015-07-10 05:53:59 +00:00
|
|
|
self.remote_user = play.remote_user
|
2015-04-07 02:31:55 +00:00
|
|
|
|
|
|
|
if play.port:
|
2015-07-10 05:53:59 +00:00
|
|
|
self.port = int(play.port)
|
2015-04-07 02:31:55 +00:00
|
|
|
|
|
|
|
if play.become is not None:
|
2015-07-10 05:53:59 +00:00
|
|
|
self.become = play.become
|
2015-04-07 02:31:55 +00:00
|
|
|
if play.become_method:
|
|
|
|
self.become_method = play.become_method
|
|
|
|
if play.become_user:
|
2015-07-10 05:53:59 +00:00
|
|
|
self.become_user = play.become_user
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-01-09 17:39:49 +00:00
|
|
|
# non connection related
|
2015-07-21 16:12:22 +00:00
|
|
|
self.no_log = play.no_log
|
|
|
|
|
2015-07-10 05:53:59 +00:00
|
|
|
if play.force_handlers is not None:
|
|
|
|
self.force_handlers = play.force_handlers
|
2015-01-09 17:39:49 +00:00
|
|
|
|
2014-11-14 22:14:08 +00: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 13:55:45 +00:00
|
|
|
lower precedence than those set on the play or host.
|
2014-11-14 22:14:08 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
if options.connection:
|
|
|
|
self.connection = options.connection
|
|
|
|
|
2015-04-07 02:31:55 +00:00
|
|
|
self.remote_user = options.remote_user
|
2015-04-24 06:47:56 +00:00
|
|
|
self.private_key_file = options.private_key_file
|
2015-04-07 02:31:55 +00:00
|
|
|
|
|
|
|
# privilege escalation
|
|
|
|
self.become = options.become
|
|
|
|
self.become_method = options.become_method
|
|
|
|
self.become_user = options.become_user
|
|
|
|
|
|
|
|
# general flags (should we move out?)
|
|
|
|
if options.verbosity:
|
|
|
|
self.verbosity = options.verbosity
|
|
|
|
#if options.no_log:
|
|
|
|
# self.no_log = boolean(options.no_log)
|
2015-01-28 14:55:18 +00:00
|
|
|
if options.check:
|
|
|
|
self.check_mode = boolean(options.check)
|
2015-07-10 07:19:48 +00:00
|
|
|
if hasattr(options, 'force_handlers') and options.force_handlers:
|
2015-07-10 05:53:59 +00:00
|
|
|
self.force_handlers = boolean(options.force_handlers)
|
2015-07-14 19:02:20 +00:00
|
|
|
if hasattr(options, 'step') and options.step:
|
|
|
|
self.step = boolean(options.step)
|
|
|
|
if hasattr(options, 'start_at_task') and options.start_at_task:
|
2015-07-22 11:45:03 +00:00
|
|
|
self.start_at_task = to_unicode(options.start_at_task)
|
2015-07-26 16:21:38 +00:00
|
|
|
if hasattr(options, 'diff') and options.diff:
|
|
|
|
self.diff = boolean(options.diff)
|
2015-01-28 14:55:18 +00:00
|
|
|
|
2014-11-14 22:14:08 +00:00
|
|
|
# get the tag info from options, converting a comma-separated list
|
2015-01-02 13:51:15 +00:00
|
|
|
# of values into a proper list if need be. We check to see if the
|
|
|
|
# options have the attribute, as it is not always added via the CLI
|
|
|
|
if hasattr(options, 'tags'):
|
|
|
|
if isinstance(options.tags, list):
|
|
|
|
self.only_tags.update(options.tags)
|
|
|
|
elif isinstance(options.tags, basestring):
|
|
|
|
self.only_tags.update(options.tags.split(','))
|
|
|
|
|
2015-01-12 22:04:56 +00:00
|
|
|
if len(self.only_tags) == 0:
|
|
|
|
self.only_tags = set(['all'])
|
|
|
|
|
2015-01-02 13:51:15 +00:00
|
|
|
if hasattr(options, 'skip_tags'):
|
|
|
|
if isinstance(options.skip_tags, list):
|
|
|
|
self.skip_tags.update(options.skip_tags)
|
|
|
|
elif isinstance(options.skip_tags, basestring):
|
|
|
|
self.skip_tags.update(options.skip_tags.split(','))
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-07-28 20:25:04 +00:00
|
|
|
def set_task_and_variable_override(self, task, variables):
|
2014-11-14 22:14:08 +00:00
|
|
|
'''
|
|
|
|
Sets attributes from the task if they are set, which will override
|
|
|
|
those from the play.
|
|
|
|
'''
|
|
|
|
|
2015-07-21 16:12:22 +00:00
|
|
|
new_info = self.copy()
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-05-11 16:22:41 +00:00
|
|
|
# loop through a subset of attributes on the task object and set
|
|
|
|
# connection fields based on their values
|
2015-07-31 21:51:26 +00:00
|
|
|
for attr in TASK_ATTRIBUTE_OVERRIDES:
|
2014-11-14 22:14:08 +00:00
|
|
|
if hasattr(task, attr):
|
|
|
|
attr_val = getattr(task, attr)
|
2015-05-22 08:32:40 +00:00
|
|
|
if attr_val is not None:
|
2015-03-20 19:13:51 +00:00
|
|
|
setattr(new_info, attr, attr_val)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-05-11 16:22:41 +00:00
|
|
|
# finally, use the MAGIC_VARIABLE_MAPPING dictionary to update this
|
2015-07-28 20:25:04 +00:00
|
|
|
# connection info object with 'magic' variables from the variable list
|
2015-05-11 16:22:41 +00:00
|
|
|
for (attr, variable_names) in MAGIC_VARIABLE_MAPPING.iteritems():
|
|
|
|
for variable_name in variable_names:
|
|
|
|
if variable_name in variables:
|
|
|
|
setattr(new_info, attr, variables[variable_name])
|
|
|
|
|
2015-07-31 16:01:32 +00:00
|
|
|
# make sure we get port defaults if needed
|
2015-07-31 17:49:48 +00:00
|
|
|
if new_info.port is None and C.DEFAULT_REMOTE_PORT is not None:
|
|
|
|
new_info.port = int(C.DEFAULT_REMOTE_PORT)
|
2015-07-31 16:01:32 +00:00
|
|
|
|
2015-07-07 03:24:00 +00:00
|
|
|
# become legacy updates
|
|
|
|
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)
|
|
|
|
|
2014-11-14 22:14:08 +00:00
|
|
|
return new_info
|
|
|
|
|
2015-06-24 16:12:54 +00:00
|
|
|
def make_become_cmd(self, cmd, executable=None):
|
2015-06-15 02:35:53 +00:00
|
|
|
""" helper function to create privilege escalation commands """
|
2015-03-13 16:57:27 +00:00
|
|
|
|
|
|
|
prompt = None
|
2015-06-15 02:35:53 +00:00
|
|
|
success_key = None
|
2015-03-13 16:57:27 +00:00
|
|
|
|
2015-06-24 16:12:54 +00:00
|
|
|
if executable is None:
|
|
|
|
executable = C.DEFAULT_EXECUTABLE
|
|
|
|
|
2015-03-13 20:31:20 +00:00
|
|
|
if self.become:
|
2015-06-15 02:35:53 +00:00
|
|
|
|
|
|
|
becomecmd = None
|
|
|
|
randbits = ''.join(chr(random.randint(ord('a'), ord('z'))) for x in xrange(32))
|
|
|
|
success_key = 'BECOME-SUCCESS-%s' % randbits
|
|
|
|
success_cmd = pipes.quote('echo %s; %s' % (success_key, cmd))
|
|
|
|
|
2015-09-02 13:29:34 +00: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 \
|
|
|
|
getattr(C, 'DEFAULT_%s_EXE' % self.become_method.upper(), None) or \
|
|
|
|
self.become_method
|
|
|
|
|
2015-03-13 20:31:20 +00:00
|
|
|
if self.become_method == 'sudo':
|
|
|
|
# Rather than detect if sudo wants a password this time, -k makes sudo always ask for
|
|
|
|
# a password if one is required. Passing a quoted compound command to sudo (or sudo -s)
|
|
|
|
# directly doesn't work, so we shellquote it with pipes.quote() and pass the quoted
|
|
|
|
# string to the user's shell. We loop reading output until we see the randomly-generated
|
|
|
|
# sudo prompt set with the -p option.
|
|
|
|
prompt = '[sudo via ansible, key=%s] password: ' % randbits
|
2015-08-15 16:05:39 +00:00
|
|
|
flags = self.become_flags or self.sudo_flags or C.DEFAULT_SUDO_FLAGS
|
|
|
|
|
|
|
|
# force quick error if password is required but not supplied, should prevent sudo hangs.
|
|
|
|
if not self.become_pass:
|
|
|
|
flags += " -n "
|
|
|
|
|
|
|
|
becomecmd = '%s %s -S -p "%s" -u %s %s -c %s' % (exe, flags, prompt, self.become_user, executable, success_cmd)
|
2015-03-13 20:31:20 +00:00
|
|
|
|
|
|
|
elif self.become_method == 'su':
|
2015-06-15 02:35:53 +00:00
|
|
|
|
|
|
|
def detect_su_prompt(data):
|
|
|
|
SU_PROMPT_LOCALIZATIONS_RE = re.compile("|".join(['(\w+\'s )?' + x + ' ?: ?' for x in SU_PROMPT_LOCALIZATIONS]), flags=re.IGNORECASE)
|
|
|
|
return bool(SU_PROMPT_LOCALIZATIONS_RE.match(data))
|
|
|
|
|
2015-06-15 05:07:02 +00:00
|
|
|
prompt = detect_su_prompt
|
2015-06-15 02:35:53 +00:00
|
|
|
flags = self.become_flags or self.su_flags or ''
|
2015-03-20 19:13:51 +00:00
|
|
|
becomecmd = '%s %s %s -c "%s -c %s"' % (exe, flags, self.become_user, executable, success_cmd)
|
2015-03-13 20:31:20 +00:00
|
|
|
|
|
|
|
elif self.become_method == 'pbrun':
|
2015-06-15 02:35:53 +00:00
|
|
|
|
|
|
|
prompt='assword:'
|
|
|
|
flags = self.become_flags or ''
|
2015-07-05 19:51:12 +00:00
|
|
|
becomecmd = '%s -b %s -u %s %s' % (exe, flags, self.become_user, success_cmd)
|
2015-03-13 20:31:20 +00:00
|
|
|
|
|
|
|
elif self.become_method == 'pfexec':
|
2015-06-15 02:35:53 +00:00
|
|
|
|
|
|
|
flags = self.become_flags or ''
|
2015-03-13 20:31:20 +00:00
|
|
|
# No user as it uses it's own exec_attr to figure it out
|
2015-03-20 19:13:51 +00:00
|
|
|
becomecmd = '%s %s "%s"' % (exe, flags, success_cmd)
|
2015-03-13 20:31:20 +00:00
|
|
|
|
2015-08-15 22:48:23 +00:00
|
|
|
elif self.become_method == 'runas':
|
|
|
|
raise AnsibleError("'runas' is not yet implemented")
|
|
|
|
#TODO: figure out prompt
|
|
|
|
# this is not for use with winrm plugin but if they ever get ssh native on windoez
|
|
|
|
flags = self.become_flags or ''
|
|
|
|
becomecmd = '%s %s /user:%s "%s"' % (exe, flags, self.become_user, success_cmd)
|
|
|
|
|
2015-08-18 01:31:18 +00:00
|
|
|
elif self.become_method == 'doas':
|
|
|
|
|
|
|
|
prompt = 'Password:'
|
|
|
|
exe = self.become_exe or 'doas'
|
|
|
|
flags = self.become_flags or ''
|
|
|
|
|
|
|
|
if not self.become_pass:
|
|
|
|
flags += ' -n '
|
|
|
|
|
|
|
|
if self.become_user:
|
|
|
|
flags += ' -u %s ' % self.become_user
|
|
|
|
|
|
|
|
becomecmd = '%s %s echo %s && %s %s env ANSIBLE=true %s' % (exe, flags, success_key, exe, flags, cmd)
|
|
|
|
|
2015-03-13 20:31:20 +00:00
|
|
|
else:
|
2015-04-14 23:04:08 +00:00
|
|
|
raise AnsibleError("Privilege escalation method not found: %s" % self.become_method)
|
2015-03-13 20:31:20 +00:00
|
|
|
|
2015-06-24 16:12:54 +00:00
|
|
|
self.prompt = prompt
|
|
|
|
self.success_key = success_key
|
2015-08-03 22:48:49 +00:00
|
|
|
return ('%s -c %s' % (executable, pipes.quote(becomecmd)))
|
2015-03-13 20:31:20 +00:00
|
|
|
|
2015-07-13 20:46:51 +00:00
|
|
|
return cmd
|
2015-06-15 02:35:53 +00:00
|
|
|
|
2015-04-15 02:10:17 +00:00
|
|
|
def update_vars(self, variables):
|
|
|
|
'''
|
|
|
|
Adds 'magic' variables relating to connections to the variable dictionary provided.
|
2015-06-15 05:02:27 +00:00
|
|
|
In case users need to access from the play, this is a legacy from runner.
|
2015-04-15 02:10:17 +00:00
|
|
|
'''
|
2015-06-15 05:02:27 +00:00
|
|
|
|
|
|
|
#FIXME: remove password? possibly add become/sudo settings
|
|
|
|
for special_var in ['ansible_connection', 'ansible_ssh_host', 'ansible_ssh_pass', 'ansible_ssh_port', 'ansible_ssh_user', 'ansible_ssh_private_key_file']:
|
|
|
|
if special_var not in variables:
|
|
|
|
for prop, varnames in MAGIC_VARIABLE_MAPPING.items():
|
|
|
|
if special_var in varnames:
|
|
|
|
variables[special_var] = getattr(self, prop)
|