2018-12-18 02:10:59 +00:00
|
|
|
# Copyright: (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
# Copyright: (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
|
|
|
|
# Copyright: (c) 2018, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
import getpass
|
2014-11-14 22:14:08 +00:00
|
|
|
import operator
|
|
|
|
import optparse
|
|
|
|
import os
|
2017-06-02 11:14:11 +00:00
|
|
|
import subprocess
|
|
|
|
import re
|
2015-05-01 02:54:38 +00:00
|
|
|
import sys
|
2014-11-14 22:14:08 +00:00
|
|
|
import time
|
|
|
|
import yaml
|
2017-06-02 11:14:11 +00:00
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
from abc import ABCMeta, abstractmethod
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2017-04-03 16:42:58 +00:00
|
|
|
import ansible
|
2014-11-14 22:14:08 +00:00
|
|
|
from ansible import constants as C
|
2018-12-18 02:10:59 +00:00
|
|
|
from ansible import context
|
2017-08-15 15:01:46 +00:00
|
|
|
from ansible.errors import AnsibleOptionsError, AnsibleError
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.inventory.manager import InventoryManager
|
|
|
|
from ansible.module_utils.six import with_metaclass, string_types
|
2016-09-07 05:54:17 +00:00
|
|
|
from ansible.module_utils._text import to_bytes, to_text
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.parsing.dataloader import DataLoader
|
2017-06-02 11:14:11 +00:00
|
|
|
from ansible.release import __version__
|
2018-11-20 23:06:51 +00:00
|
|
|
from ansible.utils.display import Display
|
2017-03-01 11:43:48 +00:00
|
|
|
from ansible.utils.path import unfrackpath
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.utils.vars import load_extra_vars, load_options_vars
|
|
|
|
from ansible.vars.manager import VariableManager
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret
|
2015-11-10 19:40:55 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
|
2018-11-20 23:06:51 +00:00
|
|
|
display = Display()
|
2015-11-10 19:40:55 +00:00
|
|
|
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
class SortedOptParser(optparse.OptionParser):
|
|
|
|
'''Optparser which sorts the options by opt before outputting --help'''
|
|
|
|
|
2015-05-01 01:22:23 +00:00
|
|
|
def format_help(self, formatter=None, epilog=None):
|
2014-11-14 22:14:08 +00:00
|
|
|
self.option_list.sort(key=operator.methodcaller('get_opt_string'))
|
|
|
|
return optparse.OptionParser.format_help(self, formatter=None)
|
|
|
|
|
2015-11-10 19:40:55 +00:00
|
|
|
|
2016-09-14 18:49:54 +00:00
|
|
|
# Note: Inherit from SortedOptParser so that we get our format_help method
|
|
|
|
class InvalidOptsParser(SortedOptParser):
|
|
|
|
'''Ignore invalid options.
|
|
|
|
|
|
|
|
Meant for the special case where we need to take care of help and version
|
|
|
|
but may not know the full range of options yet. (See it in use in set_action)
|
|
|
|
'''
|
|
|
|
def __init__(self, parser):
|
|
|
|
# Since this is special purposed to just handle help and version, we
|
|
|
|
# take a pre-existing option parser here and set our options from
|
|
|
|
# that. This allows us to give accurate help based on the given
|
|
|
|
# option parser.
|
|
|
|
SortedOptParser.__init__(self, usage=parser.usage,
|
|
|
|
option_list=parser.option_list,
|
|
|
|
option_class=parser.option_class,
|
|
|
|
conflict_handler=parser.conflict_handler,
|
|
|
|
description=parser.description,
|
|
|
|
formatter=parser.formatter,
|
|
|
|
add_help_option=False,
|
|
|
|
prog=parser.prog,
|
|
|
|
epilog=parser.epilog)
|
2017-06-02 11:14:11 +00:00
|
|
|
self.version = parser.version
|
2016-09-14 18:49:54 +00:00
|
|
|
|
|
|
|
def _process_long_opt(self, rargs, values):
|
|
|
|
try:
|
|
|
|
optparse.OptionParser._process_long_opt(self, rargs, values)
|
|
|
|
except optparse.BadOptionError:
|
|
|
|
pass
|
|
|
|
|
|
|
|
def _process_short_opts(self, rargs, values):
|
|
|
|
try:
|
|
|
|
optparse.OptionParser._process_short_opts(self, rargs, values)
|
|
|
|
except optparse.BadOptionError:
|
|
|
|
pass
|
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False,
|
|
|
|
vault_opts=False, module_opts=False, async_opts=False, connect_opts=False,
|
|
|
|
subset_opts=False, check_opts=False, inventory_opts=False, epilog=None,
|
|
|
|
fork_opts=False, runas_prompt_opts=False, desc=None, basedir_opts=False,
|
|
|
|
vault_rekey_opts=False):
|
|
|
|
"""
|
|
|
|
Create an options parser for most ansible scripts
|
|
|
|
"""
|
|
|
|
# base opts
|
|
|
|
parser = SortedOptParser(usage, version=CLI.version("%prog"), description=desc, epilog=epilog)
|
|
|
|
parser.remove_option('--version')
|
|
|
|
version_help = "show program's version number, config file location, configured module search path," \
|
|
|
|
" module location, executable location and exit"
|
|
|
|
parser.add_option('--version', action="version", help=version_help)
|
|
|
|
parser.add_option('-v', '--verbose', dest='verbosity', default=C.DEFAULT_VERBOSITY, action="count",
|
|
|
|
help="verbose mode (-vvv for more, -vvvv to enable connection debugging)")
|
|
|
|
|
|
|
|
if inventory_opts:
|
|
|
|
parser.add_option('-i', '--inventory', '--inventory-file', dest='inventory', action="append",
|
|
|
|
help="specify inventory host path or comma separated host list. --inventory-file is deprecated")
|
|
|
|
parser.add_option('--list-hosts', dest='listhosts', action='store_true',
|
|
|
|
help='outputs a list of matching hosts; does not execute anything else')
|
|
|
|
parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset',
|
|
|
|
help='further limit selected hosts to an additional pattern')
|
|
|
|
|
|
|
|
if module_opts:
|
|
|
|
parser.add_option('-M', '--module-path', dest='module_path', default=None,
|
|
|
|
help="prepend colon-separated path(s) to module library (default=%s)" % C.DEFAULT_MODULE_PATH,
|
|
|
|
action="callback", callback=CLI.unfrack_paths, type='str')
|
|
|
|
if runtask_opts:
|
|
|
|
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
|
|
|
help="set additional variables as key=value or YAML/JSON, if filename prepend with @", default=[])
|
|
|
|
|
|
|
|
if fork_opts:
|
|
|
|
parser.add_option('-f', '--forks', dest='forks', default=C.DEFAULT_FORKS, type='int',
|
|
|
|
help="specify number of parallel processes to use (default=%s)" % C.DEFAULT_FORKS)
|
|
|
|
|
|
|
|
if vault_opts:
|
|
|
|
parser.add_option('--ask-vault-pass', default=C.DEFAULT_ASK_VAULT_PASS, dest='ask_vault_pass', action='store_true',
|
|
|
|
help='ask for vault password')
|
|
|
|
parser.add_option('--vault-password-file', default=[], dest='vault_password_files',
|
|
|
|
help="vault password file", action="callback", callback=CLI.unfrack_paths, type='string')
|
|
|
|
parser.add_option('--vault-id', default=[], dest='vault_ids', action='append', type='string',
|
|
|
|
help='the vault identity to use')
|
|
|
|
|
|
|
|
if vault_rekey_opts:
|
|
|
|
parser.add_option('--new-vault-password-file', default=None, dest='new_vault_password_file',
|
|
|
|
help="new vault password file for rekey", action="callback", callback=CLI.unfrack_path, type='string')
|
|
|
|
parser.add_option('--new-vault-id', default=None, dest='new_vault_id', type='string',
|
|
|
|
help='the new vault identity to use for rekey')
|
|
|
|
|
|
|
|
if subset_opts:
|
|
|
|
parser.add_option('-t', '--tags', dest='tags', default=C.TAGS_RUN, action='append',
|
|
|
|
help="only run plays and tasks tagged with these values")
|
|
|
|
parser.add_option('--skip-tags', dest='skip_tags', default=C.TAGS_SKIP, action='append',
|
|
|
|
help="only run plays and tasks whose tags do not match these values")
|
|
|
|
|
|
|
|
if output_opts:
|
|
|
|
parser.add_option('-o', '--one-line', dest='one_line', action='store_true',
|
|
|
|
help='condense output')
|
|
|
|
parser.add_option('-t', '--tree', dest='tree', default=None,
|
|
|
|
help='log output to this directory')
|
|
|
|
|
|
|
|
if connect_opts:
|
|
|
|
connect_group = optparse.OptionGroup(parser, "Connection Options", "control as whom and how to connect to hosts")
|
|
|
|
connect_group.add_option('-k', '--ask-pass', default=C.DEFAULT_ASK_PASS, dest='ask_pass', action='store_true',
|
|
|
|
help='ask for connection password')
|
|
|
|
connect_group.add_option('--private-key', '--key-file', default=C.DEFAULT_PRIVATE_KEY_FILE, dest='private_key_file',
|
|
|
|
help='use this file to authenticate the connection', action="callback", callback=CLI.unfrack_path, type='string')
|
|
|
|
connect_group.add_option('-u', '--user', default=C.DEFAULT_REMOTE_USER, dest='remote_user',
|
|
|
|
help='connect as this user (default=%s)' % C.DEFAULT_REMOTE_USER)
|
|
|
|
connect_group.add_option('-c', '--connection', dest='connection', default=C.DEFAULT_TRANSPORT,
|
|
|
|
help="connection type to use (default=%s)" % C.DEFAULT_TRANSPORT)
|
|
|
|
connect_group.add_option('-T', '--timeout', default=C.DEFAULT_TIMEOUT, type='int', dest='timeout',
|
|
|
|
help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT)
|
|
|
|
connect_group.add_option('--ssh-common-args', default='', dest='ssh_common_args',
|
|
|
|
help="specify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand)")
|
|
|
|
connect_group.add_option('--sftp-extra-args', default='', dest='sftp_extra_args',
|
|
|
|
help="specify extra arguments to pass to sftp only (e.g. -f, -l)")
|
|
|
|
connect_group.add_option('--scp-extra-args', default='', dest='scp_extra_args',
|
|
|
|
help="specify extra arguments to pass to scp only (e.g. -l)")
|
|
|
|
connect_group.add_option('--ssh-extra-args', default='', dest='ssh_extra_args',
|
|
|
|
help="specify extra arguments to pass to ssh only (e.g. -R)")
|
|
|
|
|
|
|
|
parser.add_option_group(connect_group)
|
|
|
|
|
|
|
|
runas_group = None
|
|
|
|
rg = optparse.OptionGroup(parser, "Privilege Escalation Options", "control how and which user you become as on target hosts")
|
|
|
|
if runas_opts:
|
|
|
|
runas_group = rg
|
|
|
|
# priv user defaults to root later on to enable detecting when this option was given here
|
|
|
|
runas_group.add_option("-s", "--sudo", default=C.DEFAULT_SUDO, action="store_true", dest='sudo',
|
|
|
|
help="run operations with sudo (nopasswd) (deprecated, use become)")
|
|
|
|
runas_group.add_option('-U', '--sudo-user', dest='sudo_user', default=None,
|
|
|
|
help='desired sudo user (default=root) (deprecated, use become)')
|
|
|
|
runas_group.add_option('-S', '--su', default=C.DEFAULT_SU, action='store_true',
|
|
|
|
help='run operations with su (deprecated, use become)')
|
|
|
|
runas_group.add_option('-R', '--su-user', default=None,
|
|
|
|
help='run operations with su as this user (default=%s) (deprecated, use become)' % C.DEFAULT_SU_USER)
|
|
|
|
|
|
|
|
# consolidated privilege escalation (become)
|
|
|
|
runas_group.add_option("-b", "--become", default=C.DEFAULT_BECOME, action="store_true", dest='become',
|
|
|
|
help="run operations with become (does not imply password prompting)")
|
|
|
|
runas_group.add_option('--become-method', dest='become_method', default=C.DEFAULT_BECOME_METHOD, type='choice', choices=C.BECOME_METHODS,
|
|
|
|
help="privilege escalation method to use (default=%s), valid choices: [ %s ]" %
|
|
|
|
(C.DEFAULT_BECOME_METHOD, ' | '.join(C.BECOME_METHODS)))
|
|
|
|
runas_group.add_option('--become-user', default=None, dest='become_user', type='string',
|
|
|
|
help='run operations as this user (default=%s)' % C.DEFAULT_BECOME_USER)
|
|
|
|
|
|
|
|
if runas_opts or runas_prompt_opts:
|
|
|
|
if not runas_group:
|
|
|
|
runas_group = rg
|
|
|
|
runas_group.add_option('--ask-sudo-pass', default=C.DEFAULT_ASK_SUDO_PASS, dest='ask_sudo_pass', action='store_true',
|
|
|
|
help='ask for sudo password (deprecated, use become)')
|
|
|
|
runas_group.add_option('--ask-su-pass', default=C.DEFAULT_ASK_SU_PASS, dest='ask_su_pass', action='store_true',
|
|
|
|
help='ask for su password (deprecated, use become)')
|
|
|
|
runas_group.add_option('-K', '--ask-become-pass', default=False, dest='become_ask_pass', action='store_true',
|
|
|
|
help='ask for privilege escalation password')
|
|
|
|
|
|
|
|
if runas_group:
|
|
|
|
parser.add_option_group(runas_group)
|
|
|
|
|
|
|
|
if async_opts:
|
|
|
|
parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', dest='poll_interval',
|
|
|
|
help="set the poll interval if using -B (default=%s)" % C.DEFAULT_POLL_INTERVAL)
|
|
|
|
parser.add_option('-B', '--background', dest='seconds', type='int', default=0,
|
|
|
|
help='run asynchronously, failing after X seconds (default=N/A)')
|
|
|
|
|
|
|
|
if check_opts:
|
|
|
|
parser.add_option("-C", "--check", default=False, dest='check', action='store_true',
|
|
|
|
help="don't make any changes; instead, try to predict some of the changes that may occur")
|
|
|
|
parser.add_option('--syntax-check', dest='syntax', action='store_true',
|
|
|
|
help="perform a syntax check on the playbook, but do not execute it")
|
|
|
|
parser.add_option("-D", "--diff", default=C.DIFF_ALWAYS, dest='diff', action='store_true',
|
|
|
|
help="when changing (small) files and templates, show the differences in those files; works great with --check")
|
|
|
|
|
|
|
|
if meta_opts:
|
|
|
|
parser.add_option('--force-handlers', default=C.DEFAULT_FORCE_HANDLERS, dest='force_handlers', action='store_true',
|
|
|
|
help="run handlers even if a task fails")
|
|
|
|
parser.add_option('--flush-cache', dest='flush_cache', action='store_true',
|
|
|
|
help="clear the fact cache for every host in inventory")
|
|
|
|
|
|
|
|
if basedir_opts:
|
|
|
|
parser.add_option('--playbook-dir', default=None, dest='basedir', action='store',
|
|
|
|
help="Since this tool does not use playbooks, use this as a subsitute playbook directory."
|
|
|
|
"This sets the relative path for many features including roles/ group_vars/ etc.")
|
|
|
|
|
|
|
|
return parser
|
|
|
|
|
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
class CLI(with_metaclass(ABCMeta, object)):
|
2015-04-27 11:31:41 +00:00
|
|
|
''' code behind bin/ansible* programs '''
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2018-12-18 21:03:22 +00:00
|
|
|
VALID_ACTIONS = frozenset()
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-05-01 02:54:38 +00:00
|
|
|
_ITALIC = re.compile(r"I\(([^)]+)\)")
|
2017-06-02 11:14:11 +00:00
|
|
|
_BOLD = re.compile(r"B\(([^)]+)\)")
|
2015-05-01 02:54:38 +00:00
|
|
|
_MODULE = re.compile(r"M\(([^)]+)\)")
|
2017-06-02 11:14:11 +00:00
|
|
|
_URL = re.compile(r"U\(([^)]+)\)")
|
|
|
|
_CONST = re.compile(r"C\(([^)]+)\)")
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
PAGER = 'less'
|
2017-01-27 21:04:59 +00:00
|
|
|
|
|
|
|
# -F (quit-if-one-screen) -R (allow raw ansi control chars)
|
|
|
|
# -S (chop long lines) -X (disable termcap init and de-init)
|
|
|
|
LESS_OPTS = 'FRSX'
|
2017-10-25 23:55:48 +00:00
|
|
|
SKIP_INVENTORY_DEFAULTS = False
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2015-12-10 13:04:06 +00:00
|
|
|
def __init__(self, args, callback=None):
|
2015-04-27 11:31:41 +00:00
|
|
|
"""
|
|
|
|
Base init method for all command line programs
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.args = args
|
|
|
|
self.parser = None
|
|
|
|
self.action = None
|
2015-12-10 13:04:06 +00:00
|
|
|
self.callback = callback
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
def set_action(self):
|
|
|
|
"""
|
|
|
|
Get the action the user wants to execute from the sys argv list.
|
|
|
|
"""
|
2016-09-14 18:49:54 +00:00
|
|
|
for i in range(0, len(self.args)):
|
2015-04-27 11:31:41 +00:00
|
|
|
arg = self.args[i]
|
|
|
|
if arg in self.VALID_ACTIONS:
|
|
|
|
self.action = arg
|
|
|
|
del self.args[i]
|
|
|
|
break
|
|
|
|
|
|
|
|
if not self.action:
|
2016-09-14 18:49:54 +00:00
|
|
|
# if we're asked for help or version, we don't need an action.
|
|
|
|
# have to use a special purpose Option Parser to figure that out as
|
|
|
|
# the standard OptionParser throws an error for unknown options and
|
|
|
|
# without knowing action, we only know of a subset of the options
|
|
|
|
# that could be legal for this command
|
|
|
|
tmp_parser = InvalidOptsParser(self.parser)
|
|
|
|
tmp_options, tmp_args = tmp_parser.parse_args(self.args)
|
2016-05-31 13:30:50 +00:00
|
|
|
if not(hasattr(tmp_options, 'help') and tmp_options.help) or (hasattr(tmp_options, 'version') and tmp_options.version):
|
|
|
|
raise AnsibleOptionsError("Missing required action")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
"""
|
|
|
|
Actually runs a child defined method using the execute_<action> pattern
|
|
|
|
"""
|
|
|
|
fn = getattr(self, "execute_%s" % self.action)
|
|
|
|
fn()
|
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
@abstractmethod
|
2015-04-27 11:31:41 +00:00
|
|
|
def run(self):
|
2016-09-29 21:14:02 +00:00
|
|
|
"""Run the ansible command
|
|
|
|
|
|
|
|
Subclasses must implement this method. It does the actual work of
|
|
|
|
running an Ansible command.
|
|
|
|
"""
|
2018-12-18 02:10:59 +00:00
|
|
|
self.parse()
|
2015-07-04 14:23:30 +00:00
|
|
|
|
2017-08-04 13:25:08 +00:00
|
|
|
display.vv(to_text(self.parser.get_version()))
|
2017-05-24 18:45:35 +00:00
|
|
|
|
|
|
|
if C.CONFIG_FILE:
|
|
|
|
display.v(u"Using %s as config file" % to_text(C.CONFIG_FILE))
|
|
|
|
else:
|
|
|
|
display.v(u"No config file found; using defaults")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2017-09-14 20:56:52 +00:00
|
|
|
# warn about deprecated config options
|
2017-08-20 15:20:30 +00:00
|
|
|
for deprecated in C.config.DEPRECATED:
|
|
|
|
name = deprecated[0]
|
|
|
|
why = deprecated[1]['why']
|
2018-01-10 00:07:06 +00:00
|
|
|
if 'alternatives' in deprecated[1]:
|
|
|
|
alt = ', use %s instead' % deprecated[1]['alternatives']
|
2017-08-20 15:20:30 +00:00
|
|
|
else:
|
|
|
|
alt = ''
|
|
|
|
ver = deprecated[1]['version']
|
|
|
|
display.deprecated("%s option, %s %s" % (name, why, alt), version=ver)
|
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
@staticmethod
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
def split_vault_id(vault_id):
|
|
|
|
# return (before_@, after_@)
|
|
|
|
# if no @, return whole string as after_
|
|
|
|
if '@' not in vault_id:
|
|
|
|
return (None, vault_id)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
parts = vault_id.split('@', 1)
|
|
|
|
ret = tuple(parts)
|
|
|
|
return ret
|
2016-10-31 16:56:18 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
@staticmethod
|
2017-08-15 15:01:46 +00:00
|
|
|
def build_vault_ids(vault_ids, vault_password_files=None,
|
2017-09-19 21:39:51 +00:00
|
|
|
ask_vault_pass=None, create_new_password=None,
|
|
|
|
auto_prompt=True):
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_password_files = vault_password_files or []
|
|
|
|
vault_ids = vault_ids or []
|
2015-04-27 11:31:41 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# convert vault_password_files into vault_ids slugs
|
|
|
|
for password_file in vault_password_files:
|
|
|
|
id_slug = u'%s@%s' % (C.DEFAULT_VAULT_IDENTITY, password_file)
|
2016-10-31 16:56:18 +00:00
|
|
|
|
2018-12-14 09:42:58 +00:00
|
|
|
# note this makes --vault-id higher precedence than --vault-password-file
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# if we want to intertwingle them in order probably need a cli callback to populate vault_ids
|
|
|
|
# used by --vault-id and --vault-password-file
|
|
|
|
vault_ids.append(id_slug)
|
2016-10-31 16:56:18 +00:00
|
|
|
|
2017-08-15 15:01:46 +00:00
|
|
|
# if an action needs an encrypt password (create_new_password=True) and we dont
|
|
|
|
# have other secrets setup, then automatically add a password prompt as well.
|
2017-11-15 19:01:32 +00:00
|
|
|
# prompts cant/shouldnt work without a tty, so dont add prompt secrets
|
|
|
|
if ask_vault_pass or (not vault_ids and auto_prompt):
|
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
id_slug = u'%s@%s' % (C.DEFAULT_VAULT_IDENTITY, u'prompt_ask_vault_pass')
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_ids.append(id_slug)
|
|
|
|
|
|
|
|
return vault_ids
|
|
|
|
|
|
|
|
# TODO: remove the now unused args
|
2016-10-31 16:56:18 +00:00
|
|
|
@staticmethod
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
def setup_vault_secrets(loader, vault_ids, vault_password_files=None,
|
2017-09-19 21:39:51 +00:00
|
|
|
ask_vault_pass=None, create_new_password=False,
|
|
|
|
auto_prompt=True):
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# list of tuples
|
|
|
|
vault_secrets = []
|
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
# Depending on the vault_id value (including how --ask-vault-pass / --vault-password-file create a vault_id)
|
|
|
|
# we need to show different prompts. This is for compat with older Towers that expect a
|
|
|
|
# certain vault password prompt format, so 'promp_ask_vault_pass' vault_id gets the old format.
|
|
|
|
prompt_formats = {}
|
2017-08-01 22:07:33 +00:00
|
|
|
|
2017-08-15 15:56:17 +00:00
|
|
|
# If there are configured default vault identities, they are considered 'first'
|
|
|
|
# so we prepend them to vault_ids (from cli) here
|
|
|
|
|
2017-08-01 22:07:33 +00:00
|
|
|
vault_password_files = vault_password_files or []
|
|
|
|
if C.DEFAULT_VAULT_PASSWORD_FILE:
|
|
|
|
vault_password_files.append(C.DEFAULT_VAULT_PASSWORD_FILE)
|
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
if create_new_password:
|
2017-08-01 20:39:54 +00:00
|
|
|
prompt_formats['prompt'] = ['New vault password (%(vault_id)s): ',
|
2018-12-04 11:04:29 +00:00
|
|
|
'Confirm new vault password (%(vault_id)s): ']
|
2017-08-10 13:34:16 +00:00
|
|
|
# 2.3 format prompts for --ask-vault-pass
|
|
|
|
prompt_formats['prompt_ask_vault_pass'] = ['New Vault password: ',
|
|
|
|
'Confirm New Vault password: ']
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
else:
|
2017-08-01 20:39:54 +00:00
|
|
|
prompt_formats['prompt'] = ['Vault password (%(vault_id)s): ']
|
|
|
|
# The format when we use just --ask-vault-pass needs to match 'Vault password:\s*?$'
|
|
|
|
prompt_formats['prompt_ask_vault_pass'] = ['Vault password: ']
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
|
|
|
vault_ids = CLI.build_vault_ids(vault_ids,
|
|
|
|
vault_password_files,
|
2017-08-15 17:09:24 +00:00
|
|
|
ask_vault_pass,
|
2017-09-19 21:39:51 +00:00
|
|
|
create_new_password,
|
|
|
|
auto_prompt=auto_prompt)
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
2017-08-08 20:10:03 +00:00
|
|
|
for vault_id_slug in vault_ids:
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_id_name, vault_id_value = CLI.split_vault_id(vault_id_slug)
|
2017-08-01 20:39:54 +00:00
|
|
|
if vault_id_value in ['prompt', 'prompt_ask_vault_pass']:
|
2017-08-15 17:09:24 +00:00
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
# --vault-id some_name@prompt_ask_vault_pass --vault-id other_name@prompt_ask_vault_pass will be a little
|
|
|
|
# confusing since it will use the old format without the vault id in the prompt
|
2017-08-15 15:01:46 +00:00
|
|
|
built_vault_id = vault_id_name or C.DEFAULT_VAULT_IDENTITY
|
|
|
|
|
|
|
|
# choose the prompt based on --vault-id=prompt or --ask-vault-pass. --ask-vault-pass
|
|
|
|
# always gets the old format for Tower compatibility.
|
|
|
|
# ie, we used --ask-vault-pass, so we need to use the old vault password prompt
|
|
|
|
# format since Tower needs to match on that format.
|
|
|
|
prompted_vault_secret = PromptVaultSecret(prompt_formats=prompt_formats[vault_id_value],
|
|
|
|
vault_id=built_vault_id)
|
|
|
|
|
|
|
|
# a empty or invalid password from the prompt will warn and continue to the next
|
2018-12-14 09:42:58 +00:00
|
|
|
# without erroring globally
|
2017-08-15 15:01:46 +00:00
|
|
|
try:
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
prompted_vault_secret.load()
|
2017-08-15 15:01:46 +00:00
|
|
|
except AnsibleError as exc:
|
|
|
|
display.warning('Error in vault password prompt (%s): %s' % (vault_id_name, exc))
|
|
|
|
raise
|
|
|
|
|
|
|
|
vault_secrets.append((built_vault_id, prompted_vault_secret))
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
|
|
|
# update loader with new secrets incrementally, so we can load a vault password
|
|
|
|
# that is encrypted with a vault secret provided earlier
|
|
|
|
loader.set_vault_secrets(vault_secrets)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# assuming anything else is a password file
|
|
|
|
display.vvvvv('Reading vault password file: %s' % vault_id_value)
|
|
|
|
# read vault_pass from a file
|
|
|
|
file_vault_secret = get_file_vault_secret(filename=vault_id_value,
|
2017-10-13 19:23:08 +00:00
|
|
|
vault_id=vault_id_name,
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
loader=loader)
|
2017-08-15 15:01:46 +00:00
|
|
|
|
|
|
|
# an invalid password file will error globally
|
|
|
|
try:
|
|
|
|
file_vault_secret.load()
|
|
|
|
except AnsibleError as exc:
|
|
|
|
display.warning('Error in vault password file loading (%s): %s' % (vault_id_name, exc))
|
|
|
|
raise
|
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
if vault_id_name:
|
|
|
|
vault_secrets.append((vault_id_name, file_vault_secret))
|
|
|
|
else:
|
|
|
|
vault_secrets.append((C.DEFAULT_VAULT_IDENTITY, file_vault_secret))
|
2016-10-31 16:56:18 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# update loader with as-yet-known vault secrets
|
|
|
|
loader.set_vault_secrets(vault_secrets)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
return vault_secrets
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
def ask_passwords(self):
|
2015-04-30 22:43:53 +00:00
|
|
|
''' prompt for connection and become passwords if needed '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
op = context.CLIARGS
|
2015-04-27 11:31:41 +00:00
|
|
|
sshpass = None
|
|
|
|
becomepass = None
|
|
|
|
become_prompt = ''
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
become_prompt_method = "BECOME" if C.AGNOSTIC_BECOME_PROMPT else op['become_method'].upper()
|
2018-01-12 16:28:46 +00:00
|
|
|
|
2015-07-01 09:21:46 +00:00
|
|
|
try:
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['ask_pass']:
|
2015-07-01 09:21:46 +00:00
|
|
|
sshpass = getpass.getpass(prompt="SSH password: ")
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt = "%s password[defaults to SSH password]: " % become_prompt_method
|
2015-07-01 09:21:46 +00:00
|
|
|
if sshpass:
|
2018-07-11 14:24:45 +00:00
|
|
|
sshpass = to_bytes(sshpass, errors='strict', nonstring='simplerepr')
|
2015-07-01 09:21:46 +00:00
|
|
|
else:
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt = "%s password: " % become_prompt_method
|
2015-07-01 09:21:46 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['become_ask_pass']:
|
2015-07-01 09:21:46 +00:00
|
|
|
becomepass = getpass.getpass(prompt=become_prompt)
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['ask_pass'] and becomepass == '':
|
2015-07-01 09:21:46 +00:00
|
|
|
becomepass = sshpass
|
|
|
|
if becomepass:
|
2018-07-11 14:24:45 +00:00
|
|
|
becomepass = to_bytes(becomepass)
|
2015-07-01 09:21:46 +00:00
|
|
|
except EOFError:
|
|
|
|
pass
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
return (sshpass, becomepass)
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
@staticmethod
|
|
|
|
def normalize_become_options(options):
|
|
|
|
''' this keeps backwards compatibility with sudo/su command line options '''
|
|
|
|
if not options.become_ask_pass:
|
|
|
|
options.become_ask_pass = options.ask_sudo_pass or options.ask_su_pass or C.DEFAULT_BECOME_ASK_PASS
|
|
|
|
if not options.become_user:
|
|
|
|
options.become_user = options.sudo_user or options.su_user or C.DEFAULT_BECOME_USER
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2017-06-13 14:46:09 +00:00
|
|
|
def _dep(which):
|
2018-08-23 18:22:54 +00:00
|
|
|
display.deprecated('The %s command line option has been deprecated in favor of the "become" command line arguments' % which, '2.9')
|
2017-06-13 14:46:09 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.become:
|
2014-11-14 22:14:08 +00:00
|
|
|
pass
|
2018-12-18 02:10:59 +00:00
|
|
|
elif options.sudo:
|
|
|
|
options.become = True
|
|
|
|
options.become_method = 'sudo'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('sudo')
|
2018-12-18 02:10:59 +00:00
|
|
|
elif options.su:
|
|
|
|
options.become = True
|
|
|
|
options.become_method = 'su'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('su')
|
|
|
|
|
|
|
|
# other deprecations:
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.ask_sudo_pass or options.sudo_user:
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('sudo')
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.ask_su_pass or options.su_user:
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('su')
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
return options
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
def validate_conflicts(self, op, vault_opts=False, runas_opts=False, fork_opts=False, vault_rekey_opts=False):
|
|
|
|
''' check for conflicting options '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if vault_opts:
|
|
|
|
# Check for vault related conflicts
|
2018-12-18 02:10:59 +00:00
|
|
|
if op.ask_vault_pass and op.vault_password_files:
|
2015-06-09 21:24:06 +00:00
|
|
|
self.parser.error("--ask-vault-pass and --vault-password-file are mutually exclusive")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-01-22 22:12:10 +00:00
|
|
|
if vault_rekey_opts:
|
2018-12-18 02:10:59 +00:00
|
|
|
if op.new_vault_id and op.new_vault_password_file:
|
2018-01-22 22:12:10 +00:00
|
|
|
self.parser.error("--new-vault-password-file and --new-vault-id are mutually exclusive")
|
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if runas_opts:
|
|
|
|
# Check for privilege escalation conflicts
|
2017-03-22 02:19:40 +00:00
|
|
|
if ((op.su or op.su_user) and (op.sudo or op.sudo_user) or
|
|
|
|
(op.su or op.su_user) and (op.become or op.become_user) or
|
|
|
|
(op.sudo or op.sudo_user) and (op.become or op.become_user)):
|
2015-06-09 21:24:06 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
self.parser.error("Sudo arguments ('--sudo', '--sudo-user', and '--ask-sudo-pass')"
|
|
|
|
" and su arguments ('--su', '--su-user', and '--ask-su-pass')"
|
|
|
|
" and become arguments ('--become', '--become-user', and"
|
|
|
|
" '--ask-become-pass') are exclusive of each other")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-08-02 08:40:42 +00:00
|
|
|
if fork_opts:
|
|
|
|
if op.forks < 1:
|
|
|
|
self.parser.error("The number of processes (--forks) must be >= 1")
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
return op
|
|
|
|
|
2017-03-01 11:43:48 +00:00
|
|
|
@staticmethod
|
2017-06-14 15:08:34 +00:00
|
|
|
def unfrack_paths(option, opt, value, parser):
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
paths = getattr(parser.values, option.dest)
|
2017-09-12 01:02:16 +00:00
|
|
|
if paths is None:
|
|
|
|
paths = []
|
|
|
|
|
2017-06-14 15:08:34 +00:00
|
|
|
if isinstance(value, string_types):
|
2017-09-12 01:02:16 +00:00
|
|
|
paths[:0] = [unfrackpath(x) for x in value.split(os.pathsep) if x]
|
2017-06-15 18:32:37 +00:00
|
|
|
elif isinstance(value, list):
|
2017-09-12 01:02:16 +00:00
|
|
|
paths[:0] = [unfrackpath(x) for x in value if x]
|
2017-06-15 18:32:37 +00:00
|
|
|
else:
|
2017-06-15 22:54:05 +00:00
|
|
|
pass # FIXME: should we raise options error?
|
2017-09-12 01:02:16 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
setattr(parser.values, option.dest, paths)
|
2017-03-01 11:43:48 +00:00
|
|
|
|
2016-04-03 00:22:00 +00:00
|
|
|
@staticmethod
|
2017-06-14 15:08:34 +00:00
|
|
|
def unfrack_path(option, opt, value, parser):
|
2017-10-03 16:02:16 +00:00
|
|
|
if value != '-':
|
|
|
|
setattr(parser.values, option.dest, unfrackpath(value))
|
|
|
|
else:
|
|
|
|
setattr(parser.values, option.dest, value)
|
2016-04-03 00:22:00 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
@abstractmethod
|
|
|
|
def init_parser(self, usage="", output_opts=False, runas_opts=False, meta_opts=False,
|
|
|
|
runtask_opts=False, vault_opts=False, module_opts=False, async_opts=False,
|
|
|
|
connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False,
|
|
|
|
epilog=None, fork_opts=False, runas_prompt_opts=False, desc=None,
|
|
|
|
basedir_opts=False, vault_rekey_opts=False):
|
|
|
|
"""
|
|
|
|
Create an options parser for most ansible scripts
|
2015-05-01 01:22:23 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
Subclasses need to implement this method. They will usually call the base class's
|
|
|
|
init_parser to create a basic version and then add their own options on top of that.
|
2015-06-09 21:24:06 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
An implementation will look something like this::
|
2017-12-07 04:50:51 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
def init_parser(self):
|
|
|
|
self.parser = super(MyCLI, self).init__parser(usage="My Ansible CLI", inventory_opts=True)
|
|
|
|
self.parser.add_option('--my-option', dest='my_option', action='store')
|
|
|
|
return self.parser
|
|
|
|
"""
|
|
|
|
self.parser = base_parser(usage=usage, output_opts=output_opts, runas_opts=runas_opts,
|
|
|
|
meta_opts=meta_opts, runtask_opts=runtask_opts,
|
|
|
|
vault_opts=vault_opts, module_opts=module_opts,
|
|
|
|
async_opts=async_opts, connect_opts=connect_opts,
|
|
|
|
subset_opts=subset_opts, check_opts=check_opts,
|
|
|
|
inventory_opts=inventory_opts, epilog=epilog, fork_opts=fork_opts,
|
|
|
|
runas_prompt_opts=runas_prompt_opts, desc=desc,
|
|
|
|
basedir_opts=basedir_opts, vault_rekey_opts=vault_rekey_opts)
|
|
|
|
return self.parser
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
@abstractmethod
|
2018-12-18 02:10:59 +00:00
|
|
|
def post_process_args(self, options, args):
|
|
|
|
"""Process the command line args
|
|
|
|
|
|
|
|
Subclasses need to implement this method. This method validates and transforms the command
|
|
|
|
line arguments. It can be used to check whether conflicting values were given, whether filenames
|
|
|
|
exist, etc.
|
|
|
|
|
|
|
|
An implementation will look something like this::
|
|
|
|
|
|
|
|
def post_process_args(self, options, args):
|
|
|
|
options, args = super(MyCLI, self).post_process_args(options, args)
|
|
|
|
if options.addition and options.subtraction:
|
|
|
|
raise AnsibleOptionsError('Only one of --addition and --subtraction can be specified')
|
|
|
|
if isinstance(options.listofhosts, string_types):
|
|
|
|
options.listofhosts = string_types.split(',')
|
|
|
|
return options, args
|
2016-09-29 21:14:02 +00:00
|
|
|
"""
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# process tags
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'tags') and not options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
# optparse defaults does not do what's expected
|
2018-12-18 02:10:59 +00:00
|
|
|
options.tags = ['all']
|
|
|
|
if hasattr(options, 'tags') and options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
tags = set()
|
2018-12-18 02:10:59 +00:00
|
|
|
for tag_set in options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
tags.add(tag.strip())
|
2018-12-18 02:10:59 +00:00
|
|
|
options.tags = list(tags)
|
2016-09-29 21:14:02 +00:00
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
# process skip_tags
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'skip_tags') and options.skip_tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
skip_tags = set()
|
2018-12-18 02:10:59 +00:00
|
|
|
for tag_set in options.skip_tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
skip_tags.add(tag.strip())
|
2018-12-18 02:10:59 +00:00
|
|
|
options.skip_tags = list(skip_tags)
|
2016-09-29 21:14:02 +00:00
|
|
|
|
2017-10-25 23:55:48 +00:00
|
|
|
# process inventory options except for CLIs that require their own processing
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'inventory') and not self.SKIP_INVENTORY_DEFAULTS:
|
2017-05-23 21:16:49 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.inventory:
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# should always be list
|
2018-12-18 02:10:59 +00:00
|
|
|
if isinstance(options.inventory, string_types):
|
|
|
|
options.inventory = [options.inventory]
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# Ensure full paths when needed
|
2018-12-18 02:10:59 +00:00
|
|
|
options.inventory = [unfrackpath(opt, follow=False) if ',' not in opt else opt for opt in options.inventory]
|
2017-05-23 21:16:49 +00:00
|
|
|
else:
|
2018-12-18 02:10:59 +00:00
|
|
|
options.inventory = C.DEFAULT_HOST_LIST
|
|
|
|
|
|
|
|
return options, args
|
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
"""Parse the command line args
|
|
|
|
|
|
|
|
This method parses the command line arguments. It uses the parser
|
|
|
|
stored in the self.parser attribute and saves the args and options in
|
|
|
|
context.CLIARGS.
|
|
|
|
|
|
|
|
Subclasses need to implement two helper methods, init_parser() and post_process_args() which
|
|
|
|
are called from this function before and after parsing the arguments.
|
|
|
|
"""
|
|
|
|
self.init_parser()
|
|
|
|
options, args = self.parser.parse_args(self.args[1:])
|
|
|
|
options, args = self.post_process_args(options, args)
|
|
|
|
options.args = args
|
|
|
|
context._init_global_context(options)
|
2017-05-23 21:16:49 +00:00
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
@staticmethod
|
|
|
|
def version(prog):
|
2015-04-30 22:43:53 +00:00
|
|
|
''' return ansible version '''
|
2015-04-27 11:31:41 +00:00
|
|
|
result = "{0} {1}".format(prog, __version__)
|
2015-05-01 01:22:23 +00:00
|
|
|
gitinfo = CLI._gitinfo()
|
2015-04-27 11:31:41 +00:00
|
|
|
if gitinfo:
|
|
|
|
result = result + " {0}".format(gitinfo)
|
2015-07-23 19:32:39 +00:00
|
|
|
result += "\n config file = %s" % C.CONFIG_FILE
|
2015-11-05 19:26:23 +00:00
|
|
|
if C.DEFAULT_MODULE_PATH is None:
|
|
|
|
cpath = "Default w/o overrides"
|
|
|
|
else:
|
|
|
|
cpath = C.DEFAULT_MODULE_PATH
|
|
|
|
result = result + "\n configured module search path = %s" % cpath
|
2017-04-03 16:42:58 +00:00
|
|
|
result = result + "\n ansible python module location = %s" % ':'.join(ansible.__path__)
|
2017-04-03 18:01:59 +00:00
|
|
|
result = result + "\n executable location = %s" % sys.argv[0]
|
2017-03-03 21:41:54 +00:00
|
|
|
result = result + "\n python version = %s" % ''.join(sys.version.splitlines())
|
2015-04-27 11:31:41 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def version_info(gitinfo=False):
|
2015-04-30 22:43:53 +00:00
|
|
|
''' return full ansible version info '''
|
2015-04-27 11:31:41 +00:00
|
|
|
if gitinfo:
|
|
|
|
# expensive call, user with care
|
2015-10-01 18:14:02 +00:00
|
|
|
ansible_version_string = CLI.version('')
|
2015-04-27 11:31:41 +00:00
|
|
|
else:
|
|
|
|
ansible_version_string = __version__
|
|
|
|
ansible_version = ansible_version_string.split()[0]
|
|
|
|
ansible_versions = ansible_version.split('.')
|
|
|
|
for counter in range(len(ansible_versions)):
|
|
|
|
if ansible_versions[counter] == "":
|
|
|
|
ansible_versions[counter] = 0
|
|
|
|
try:
|
|
|
|
ansible_versions[counter] = int(ansible_versions[counter])
|
2018-06-29 23:45:38 +00:00
|
|
|
except Exception:
|
2015-04-27 11:31:41 +00:00
|
|
|
pass
|
|
|
|
if len(ansible_versions) < 3:
|
|
|
|
for counter in range(len(ansible_versions), 3):
|
|
|
|
ansible_versions.append(0)
|
2017-06-02 11:14:11 +00:00
|
|
|
return {'string': ansible_version_string.strip(),
|
|
|
|
'full': ansible_version,
|
|
|
|
'major': ansible_versions[0],
|
|
|
|
'minor': ansible_versions[1],
|
|
|
|
'revision': ansible_versions[2]}
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2015-04-30 22:43:53 +00:00
|
|
|
@staticmethod
|
|
|
|
def _git_repo_info(repo_path):
|
|
|
|
''' returns a string containing git branch, commit id and commit date '''
|
|
|
|
result = None
|
|
|
|
if os.path.exists(repo_path):
|
|
|
|
# Check if the .git is a file. If it is a file, it means that we are in a submodule structure.
|
|
|
|
if os.path.isfile(repo_path):
|
|
|
|
try:
|
|
|
|
gitdir = yaml.safe_load(open(repo_path)).get('gitdir')
|
|
|
|
# There is a possibility the .git file to have an absolute path.
|
|
|
|
if os.path.isabs(gitdir):
|
|
|
|
repo_path = gitdir
|
|
|
|
else:
|
|
|
|
repo_path = os.path.join(repo_path[:-4], gitdir)
|
|
|
|
except (IOError, AttributeError):
|
|
|
|
return ''
|
|
|
|
f = open(os.path.join(repo_path, "HEAD"))
|
2015-08-03 08:12:47 +00:00
|
|
|
line = f.readline().rstrip("\n")
|
|
|
|
if line.startswith("ref:"):
|
|
|
|
branch_path = os.path.join(repo_path, line[5:])
|
|
|
|
else:
|
|
|
|
branch_path = None
|
2014-11-14 22:14:08 +00:00
|
|
|
f.close()
|
2015-08-03 08:12:47 +00:00
|
|
|
if branch_path and os.path.exists(branch_path):
|
|
|
|
branch = '/'.join(line.split('/')[2:])
|
2015-04-30 22:43:53 +00:00
|
|
|
f = open(branch_path)
|
|
|
|
commit = f.readline()[:10]
|
|
|
|
f.close()
|
|
|
|
else:
|
|
|
|
# detached HEAD
|
2015-08-03 08:12:47 +00:00
|
|
|
commit = line[:10]
|
2015-04-30 22:43:53 +00:00
|
|
|
branch = 'detached HEAD'
|
|
|
|
branch_path = os.path.join(repo_path, "HEAD")
|
|
|
|
|
|
|
|
date = time.localtime(os.stat(branch_path).st_mtime)
|
|
|
|
if time.daylight == 0:
|
|
|
|
offset = time.timezone
|
|
|
|
else:
|
|
|
|
offset = time.altzone
|
2017-06-02 11:14:11 +00:00
|
|
|
result = "({0} {1}) last updated {2} (GMT {3:+04d})".format(branch, commit, time.strftime("%Y/%m/%d %H:%M:%S", date), int(offset / -36))
|
2014-11-14 22:14:08 +00:00
|
|
|
else:
|
2015-04-30 22:43:53 +00:00
|
|
|
result = ''
|
|
|
|
return result
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _gitinfo():
|
|
|
|
basedir = os.path.join(os.path.dirname(__file__), '..', '..', '..')
|
|
|
|
repo_path = os.path.join(basedir, '.git')
|
2015-05-01 01:22:23 +00:00
|
|
|
result = CLI._git_repo_info(repo_path)
|
2015-04-30 22:43:53 +00:00
|
|
|
submodules = os.path.join(basedir, '.gitmodules')
|
|
|
|
if not os.path.exists(submodules):
|
2015-11-10 19:40:55 +00:00
|
|
|
return result
|
2015-04-30 22:43:53 +00:00
|
|
|
f = open(submodules)
|
|
|
|
for line in f:
|
|
|
|
tokens = line.strip().split(' ')
|
|
|
|
if tokens[0] == 'path':
|
|
|
|
submodule_path = tokens[2]
|
2015-05-01 01:22:23 +00:00
|
|
|
submodule_info = CLI._git_repo_info(os.path.join(basedir, submodule_path, '.git'))
|
2015-04-30 22:43:53 +00:00
|
|
|
if not submodule_info:
|
|
|
|
submodule_info = ' not found - use git submodule update --init ' + submodule_path
|
|
|
|
result += "\n {0}: {1}".format(submodule_path, submodule_info)
|
|
|
|
f.close()
|
|
|
|
return result
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2015-08-15 02:00:15 +00:00
|
|
|
def pager(self, text):
|
2015-05-01 02:54:38 +00:00
|
|
|
''' find reasonable way to display text '''
|
|
|
|
# this is a much simpler form of what is in pydoc.py
|
|
|
|
if not sys.stdout.isatty():
|
2017-06-15 14:45:01 +00:00
|
|
|
display.display(text, screen_only=True)
|
2015-05-01 02:54:38 +00:00
|
|
|
elif 'PAGER' in os.environ:
|
|
|
|
if sys.platform == 'win32':
|
2017-06-15 14:45:01 +00:00
|
|
|
display.display(text, screen_only=True)
|
2015-05-01 02:54:38 +00:00
|
|
|
else:
|
2015-08-15 02:00:15 +00:00
|
|
|
self.pager_pipe(text, os.environ['PAGER'])
|
2015-05-01 02:54:38 +00:00
|
|
|
else:
|
2016-09-09 13:30:37 +00:00
|
|
|
p = subprocess.Popen('less --version', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
p.communicate()
|
|
|
|
if p.returncode == 0:
|
|
|
|
self.pager_pipe(text, 'less')
|
|
|
|
else:
|
2017-06-15 14:45:01 +00:00
|
|
|
display.display(text, screen_only=True)
|
2015-05-01 02:54:38 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def pager_pipe(text, cmd):
|
|
|
|
''' pipe text through a pager '''
|
|
|
|
if 'LESS' not in os.environ:
|
2015-05-12 16:26:20 +00:00
|
|
|
os.environ['LESS'] = CLI.LESS_OPTS
|
2015-05-01 02:54:38 +00:00
|
|
|
try:
|
|
|
|
cmd = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
|
2016-01-28 18:50:20 +00:00
|
|
|
cmd.communicate(input=to_bytes(text))
|
2015-05-01 02:54:38 +00:00
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
2015-10-09 04:46:31 +00:00
|
|
|
def tty_ify(cls, text):
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2015-10-09 04:46:31 +00:00
|
|
|
t = cls._ITALIC.sub("`" + r"\1" + "'", text) # I(word) => `word'
|
|
|
|
t = cls._BOLD.sub("*" + r"\1" + "*", t) # B(word) => *word*
|
|
|
|
t = cls._MODULE.sub("[" + r"\1" + "]", t) # M(word) => [word]
|
|
|
|
t = cls._URL.sub(r"\1", t) # U(word) => word
|
|
|
|
t = cls._CONST.sub("`" + r"\1" + "'", t) # C(word) => `word'
|
2015-05-01 02:54:38 +00:00
|
|
|
|
|
|
|
return t
|
2015-07-11 18:24:45 +00:00
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
@staticmethod
|
2018-12-18 02:10:59 +00:00
|
|
|
def _play_prereqs():
|
|
|
|
options = context.CLIARGS
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# all needs loader
|
|
|
|
loader = DataLoader()
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
basedir = options.get('basedir', False)
|
2017-10-31 19:41:30 +00:00
|
|
|
if basedir:
|
|
|
|
loader.set_basedir(basedir)
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
vault_ids = list(options['vault_ids'])
|
2017-08-28 14:13:14 +00:00
|
|
|
default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST
|
|
|
|
vault_ids = default_vault_ids + vault_ids
|
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_secrets = CLI.setup_vault_secrets(loader,
|
2017-08-28 14:13:14 +00:00
|
|
|
vault_ids=vault_ids,
|
2018-12-18 02:10:59 +00:00
|
|
|
vault_password_files=list(options['vault_password_files']),
|
|
|
|
ask_vault_pass=options['ask_vault_pass'],
|
2017-09-19 21:39:51 +00:00
|
|
|
auto_prompt=False)
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
loader.set_vault_secrets(vault_secrets)
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# create the inventory, and filter it based on the subset specified (if any)
|
2018-12-18 02:10:59 +00:00
|
|
|
inventory = InventoryManager(loader=loader, sources=options['inventory'])
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# create the variable manager, which will be shared throughout
|
|
|
|
# the code, ensuring a consistent view of global variables
|
|
|
|
variable_manager = VariableManager(loader=loader, inventory=inventory)
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
# If the basedir is specified as the empty string then it results in cwd being used. This
|
|
|
|
# is not a safe location to load vars from
|
|
|
|
if options.get('basedir', False) is not False:
|
|
|
|
if basedir:
|
2018-06-29 23:45:38 +00:00
|
|
|
variable_manager.safe_basedir = True
|
|
|
|
else:
|
|
|
|
variable_manager.safe_basedir = True
|
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
# load vars from cli options
|
2018-12-18 02:10:59 +00:00
|
|
|
variable_manager.extra_vars = load_extra_vars(loader=loader)
|
|
|
|
variable_manager.options_vars = load_options_vars(CLI.version_info(gitinfo=False))
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
return loader, inventory, variable_manager
|
2017-12-15 20:43:51 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_host_list(inventory, subset, pattern='all'):
|
|
|
|
|
|
|
|
no_hosts = False
|
|
|
|
if len(inventory.list_hosts()) == 0:
|
|
|
|
# Empty inventory
|
2018-11-07 16:09:32 +00:00
|
|
|
if C.LOCALHOST_WARNING and pattern not in C.LOCALHOST:
|
2018-03-24 12:59:19 +00:00
|
|
|
display.warning("provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'")
|
2017-12-15 20:43:51 +00:00
|
|
|
no_hosts = True
|
|
|
|
|
|
|
|
inventory.subset(subset)
|
|
|
|
|
|
|
|
hosts = inventory.list_hosts(pattern)
|
|
|
|
if len(hosts) == 0 and no_hosts is False:
|
|
|
|
raise AnsibleError("Specified hosts and/or --limit does not match any hosts")
|
|
|
|
|
|
|
|
return hosts
|