2014-11-14 22:14:08 +00:00
|
|
|
# (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
2016-09-14 18:49:54 +00:00
|
|
|
# (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
|
2014-11-14 22:14:08 +00:00
|
|
|
#
|
|
|
|
# This file is part of Ansible
|
|
|
|
#
|
|
|
|
# Ansible is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# Ansible is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
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
|
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__
|
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
|
|
|
|
|
|
|
try:
|
|
|
|
from __main__ import display
|
|
|
|
except ImportError:
|
|
|
|
from ansible.utils.display import Display
|
|
|
|
display = Display()
|
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2017-03-23 05:11:40 +00:00
|
|
|
VALID_ACTIONS = []
|
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.options = None
|
|
|
|
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.
|
|
|
|
"""
|
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)
|
|
|
|
|
2017-09-14 20:56:52 +00:00
|
|
|
# warn about typing issues with configuration entries
|
|
|
|
for unable in C.config.UNABLE:
|
|
|
|
display.warning("Unable to set correct type for configuration entry: %s" % unable)
|
|
|
|
|
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
|
|
|
|
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
|
|
|
# note this makes --vault-id higher precendence than --vault-password-file
|
|
|
|
# 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): ',
|
|
|
|
'Confirm vew 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
|
|
|
|
# without erroring globablly
|
|
|
|
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
|
|
|
|
|
|
|
op = self.options
|
|
|
|
sshpass = None
|
|
|
|
becomepass = None
|
|
|
|
become_prompt = ''
|
|
|
|
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt_method = "BECOME" if C.AGNOSTIC_BECOME_PROMPT else op.become_method.upper()
|
|
|
|
|
2015-07-01 09:21:46 +00:00
|
|
|
try:
|
|
|
|
if op.ask_pass:
|
|
|
|
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:
|
|
|
|
sshpass = to_bytes(sshpass, errors='strict', nonstring='simplerepr')
|
|
|
|
else:
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt = "%s password: " % become_prompt_method
|
2015-07-01 09:21:46 +00:00
|
|
|
|
|
|
|
if op.become_ask_pass:
|
|
|
|
becomepass = getpass.getpass(prompt=become_prompt)
|
|
|
|
if op.ask_pass and becomepass == '':
|
|
|
|
becomepass = sshpass
|
|
|
|
if becomepass:
|
|
|
|
becomepass = to_bytes(becomepass)
|
|
|
|
except EOFError:
|
|
|
|
pass
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
return (sshpass, becomepass)
|
|
|
|
|
|
|
|
def normalize_become_options(self):
|
|
|
|
''' this keeps backwards compatibility with sudo/su self.options '''
|
|
|
|
self.options.become_ask_pass = self.options.become_ask_pass or self.options.ask_sudo_pass or self.options.ask_su_pass or C.DEFAULT_BECOME_ASK_PASS
|
2017-06-02 11:14:11 +00:00
|
|
|
self.options.become_user = self.options.become_user or self.options.sudo_user or self.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):
|
|
|
|
display.deprecated('The %s command line option has been deprecated in favor of the "become" command line arguments' % which, '2.6')
|
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
if self.options.become:
|
2014-11-14 22:14:08 +00:00
|
|
|
pass
|
2015-04-27 11:31:41 +00:00
|
|
|
elif self.options.sudo:
|
|
|
|
self.options.become = True
|
|
|
|
self.options.become_method = 'sudo'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('sudo')
|
2015-04-27 11:31:41 +00:00
|
|
|
elif self.options.su:
|
|
|
|
self.options.become = True
|
2015-07-01 04:16:01 +00:00
|
|
|
self.options.become_method = 'su'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('su')
|
|
|
|
|
|
|
|
# other deprecations:
|
|
|
|
if self.options.ask_sudo_pass or self.options.sudo_user:
|
|
|
|
_dep('sudo')
|
|
|
|
if self.options.ask_su_pass or self.options.su_user:
|
|
|
|
_dep('su')
|
|
|
|
|
2018-01-22 22:12:10 +00:00
|
|
|
def validate_conflicts(self, vault_opts=False, runas_opts=False, fork_opts=False, vault_rekey_opts=False):
|
2015-04-30 22:43:53 +00:00
|
|
|
''' check for conflicting options '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
op = self.options
|
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if vault_opts:
|
|
|
|
# Check for vault related conflicts
|
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 (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:
|
|
|
|
if (op.new_vault_id and op.new_vault_password_file):
|
|
|
|
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
|
|
|
|
2017-06-14 15:08:34 +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")
|
|
|
|
|
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
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
@staticmethod
|
2015-08-25 22:10:03 +00:00
|
|
|
def base_parser(usage="", output_opts=False, runas_opts=False, meta_opts=False, runtask_opts=False, vault_opts=False, module_opts=False,
|
2017-06-02 11:14:11 +00:00
|
|
|
async_opts=False, connect_opts=False, subset_opts=False, check_opts=False, inventory_opts=False, epilog=None, fork_opts=False,
|
2017-12-07 04:50:51 +00:00
|
|
|
runas_prompt_opts=False, desc=None, basedir_opts=False, vault_rekey_opts=False):
|
2015-04-30 22:43:53 +00:00
|
|
|
''' create an options parser for most ansible scripts '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-05-01 01:22:23 +00:00
|
|
|
# base opts
|
2017-03-22 20:38:49 +00:00
|
|
|
parser = SortedOptParser(usage, version=CLI.version("%prog"), description=desc, epilog=epilog)
|
2017-06-02 11:14:11 +00:00
|
|
|
parser.add_option('-v', '--verbose', dest='verbosity', default=C.DEFAULT_VERBOSITY, action="count",
|
|
|
|
help="verbose mode (-vvv for more, -vvvv to enable connection debugging)")
|
2015-05-01 01:22:23 +00:00
|
|
|
|
2015-08-18 07:17:58 +00:00
|
|
|
if inventory_opts:
|
2017-05-23 21:16:49 +00:00
|
|
|
parser.add_option('-i', '--inventory', '--inventory-file', dest='inventory', action="append",
|
2017-10-25 23:55:48 +00:00
|
|
|
help="specify inventory host path or comma separated host list. --inventory-file is deprecated")
|
2015-05-01 01:22:23 +00:00
|
|
|
parser.add_option('--list-hosts', dest='listhosts', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='outputs a list of matching hosts; does not execute anything else')
|
2015-08-18 07:17:58 +00:00
|
|
|
parser.add_option('-l', '--limit', default=C.DEFAULT_SUBSET, dest='subset',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='further limit selected hosts to an additional pattern')
|
2015-08-18 07:17:58 +00:00
|
|
|
|
2015-08-25 22:10:03 +00:00
|
|
|
if module_opts:
|
|
|
|
parser.add_option('-M', '--module-path', dest='module_path', default=None,
|
2017-09-12 01:02:16 +00:00
|
|
|
help="prepend colon-separated path(s) to module library (default=%s)" % C.DEFAULT_MODULE_PATH,
|
|
|
|
action="callback", callback=CLI.unfrack_paths, type='str')
|
2015-08-25 22:10:03 +00:00
|
|
|
if runtask_opts:
|
2015-05-01 01:22:23 +00:00
|
|
|
parser.add_option('-e', '--extra-vars', dest="extra_vars", action="append",
|
2017-05-17 01:11:12 +00:00
|
|
|
help="set additional variables as key=value or YAML/JSON, if filename prepend with @", default=[])
|
2015-05-01 01:22:23 +00:00
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if fork_opts:
|
2017-06-02 11:14:11 +00:00
|
|
|
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)
|
2015-06-09 21:24:06 +00:00
|
|
|
|
2015-05-01 01:22:23 +00:00
|
|
|
if vault_opts:
|
2015-12-14 13:36:35 +00:00
|
|
|
parser.add_option('--ask-vault-pass', default=C.DEFAULT_ASK_VAULT_PASS, dest='ask_vault_pass', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='ask for 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
|
|
|
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')
|
2017-12-07 04:50:51 +00:00
|
|
|
|
|
|
|
if vault_rekey_opts:
|
2018-01-22 22:12:10 +00:00
|
|
|
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')
|
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
|
|
|
parser.add_option('--new-vault-id', default=None, dest='new_vault_id', type='string',
|
|
|
|
help='the new vault identity to use for rekey')
|
2015-07-28 09:48:57 +00:00
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
if subset_opts:
|
2017-09-21 20:23:16 +00:00
|
|
|
parser.add_option('-t', '--tags', dest='tags', default=C.TAGS_RUN, action='append',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="only run plays and tasks tagged with these values")
|
2017-09-21 20:23:16 +00:00
|
|
|
parser.add_option('--skip-tags', dest='skip_tags', default=C.TAGS_SKIP, action='append',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="only run plays and tasks whose tags do not match these values")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
if output_opts:
|
|
|
|
parser.add_option('-o', '--one-line', dest='one_line', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='condense output')
|
2015-04-27 11:31:41 +00:00
|
|
|
parser.add_option('-t', '--tree', dest='tree', default=None,
|
2017-06-02 11:14:11 +00:00
|
|
|
help='log output to this directory')
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2016-01-27 16:09:29 +00:00
|
|
|
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',
|
2017-06-02 11:14:11 +00:00
|
|
|
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')
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('-u', '--user', default=C.DEFAULT_REMOTE_USER, dest='remote_user',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='connect as this user (default=%s)' % C.DEFAULT_REMOTE_USER)
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('-c', '--connection', dest='connection', default=C.DEFAULT_TRANSPORT,
|
2017-06-02 11:14:11 +00:00
|
|
|
help="connection type to use (default=%s)" % C.DEFAULT_TRANSPORT)
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('-T', '--timeout', default=C.DEFAULT_TIMEOUT, type='int', dest='timeout',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="override the connection timeout in seconds (default=%s)" % C.DEFAULT_TIMEOUT)
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('--ssh-common-args', default='', dest='ssh_common_args',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="specify common arguments to pass to sftp/scp/ssh (e.g. ProxyCommand)")
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('--sftp-extra-args', default='', dest='sftp_extra_args',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="specify extra arguments to pass to sftp only (e.g. -f, -l)")
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('--scp-extra-args', default='', dest='scp_extra_args',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="specify extra arguments to pass to scp only (e.g. -l)")
|
2016-01-27 16:09:29 +00:00
|
|
|
connect_group.add_option('--ssh-extra-args', default='', dest='ssh_extra_args',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="specify extra arguments to pass to ssh only (e.g. -R)")
|
2016-01-27 16:09:29 +00:00
|
|
|
|
|
|
|
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")
|
2015-04-27 11:31:41 +00:00
|
|
|
if runas_opts:
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group = rg
|
2015-04-27 11:31:41 +00:00
|
|
|
# priv user defaults to root later on to enable detecting when this option was given here
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option("-s", "--sudo", default=C.DEFAULT_SUDO, action="store_true", dest='sudo',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="run operations with sudo (nopasswd) (deprecated, use become)")
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('-U', '--sudo-user', dest='sudo_user', default=None,
|
2017-06-02 11:14:11 +00:00
|
|
|
help='desired sudo user (default=root) (deprecated, use become)')
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('-S', '--su', default=C.DEFAULT_SU, action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='run operations with su (deprecated, use become)')
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('-R', '--su-user', default=None,
|
2017-06-02 11:14:11 +00:00
|
|
|
help='run operations with su as this user (default=%s) (deprecated, use become)' % C.DEFAULT_SU_USER)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
# consolidated privilege escalation (become)
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option("-b", "--become", default=C.DEFAULT_BECOME, action="store_true", dest='become',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="run operations with become (does not imply password prompting)")
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('--become-method', dest='become_method', default=C.DEFAULT_BECOME_METHOD, type='choice', choices=C.BECOME_METHODS,
|
2017-06-02 11:14:11 +00:00
|
|
|
help="privilege escalation method to use (default=%s), valid choices: [ %s ]" %
|
|
|
|
(C.DEFAULT_BECOME_METHOD, ' | '.join(C.BECOME_METHODS)))
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('--become-user', default=None, dest='become_user', type='string',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='run operations as this user (default=%s)' % C.DEFAULT_BECOME_USER)
|
2015-12-04 04:47:02 +00:00
|
|
|
|
|
|
|
if runas_opts or runas_prompt_opts:
|
2016-01-27 16:09:29 +00:00
|
|
|
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',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='ask for sudo password (deprecated, use become)')
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('--ask-su-pass', default=C.DEFAULT_ASK_SU_PASS, dest='ask_su_pass', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='ask for su password (deprecated, use become)')
|
2016-01-27 16:09:29 +00:00
|
|
|
runas_group.add_option('-K', '--ask-become-pass', default=False, dest='become_ask_pass', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help='ask for privilege escalation password')
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2016-01-27 16:09:29 +00:00
|
|
|
if runas_group:
|
|
|
|
parser.add_option_group(runas_group)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
if async_opts:
|
2015-08-17 00:05:10 +00:00
|
|
|
parser.add_option('-P', '--poll', default=C.DEFAULT_POLL_INTERVAL, type='int', dest='poll_interval',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="set the poll interval if using -B (default=%s)" % C.DEFAULT_POLL_INTERVAL)
|
2015-04-27 11:31:41 +00:00
|
|
|
parser.add_option('-B', '--background', dest='seconds', type='int', default=0,
|
2017-06-02 11:14:11 +00:00
|
|
|
help='run asynchronously, failing after X seconds (default=N/A)')
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
if check_opts:
|
|
|
|
parser.add_option("-C", "--check", default=False, dest='check', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="don't make any changes; instead, try to predict some of the changes that may occur")
|
2015-04-27 11:31:41 +00:00
|
|
|
parser.add_option('--syntax-check', dest='syntax', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="perform a syntax check on the playbook, but do not execute it")
|
2017-08-04 14:42:38 +00:00
|
|
|
parser.add_option("-D", "--diff", default=C.DIFF_ALWAYS, dest='diff', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="when changing (small) files and templates, show the differences in those files; works great with --check")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
if meta_opts:
|
2015-07-10 05:53:59 +00:00
|
|
|
parser.add_option('--force-handlers', default=C.DEFAULT_FORCE_HANDLERS, dest='force_handlers', action='store_true',
|
2017-06-02 11:14:11 +00:00
|
|
|
help="run handlers even if a task fails")
|
2015-04-27 11:31:41 +00:00
|
|
|
parser.add_option('--flush-cache', dest='flush_cache', action='store_true',
|
2017-11-15 15:40:35 +00:00
|
|
|
help="clear the fact cache for every host in inventory")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2017-10-31 19:41:30 +00:00
|
|
|
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.")
|
2015-04-27 11:31:41 +00:00
|
|
|
return parser
|
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
@abstractmethod
|
|
|
|
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
|
|
|
|
self.args and self.options respectively.
|
|
|
|
|
|
|
|
Subclasses need to implement this method. They will usually create
|
|
|
|
a base_parser, add their own options to the base_parser, and then call
|
|
|
|
this method to do the actual parsing. An implementation will look
|
|
|
|
something like this::
|
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
parser = super(MyCLI, self).base_parser(usage="My Ansible CLI", inventory_opts=True)
|
|
|
|
parser.add_option('--my-option', dest='my_option', action='store')
|
|
|
|
self.parser = parser
|
|
|
|
super(MyCLI, self).parse()
|
|
|
|
# If some additional transformations are needed for the
|
|
|
|
# arguments and options, do it here.
|
|
|
|
"""
|
2017-05-23 21:16:49 +00:00
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
self.options, self.args = self.parser.parse_args(self.args[1:])
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# process tags
|
2016-09-29 21:14:02 +00:00
|
|
|
if hasattr(self.options, 'tags') and not self.options.tags:
|
|
|
|
# optparse defaults does not do what's expected
|
|
|
|
self.options.tags = ['all']
|
|
|
|
if hasattr(self.options, 'tags') and self.options.tags:
|
|
|
|
if not C.MERGE_MULTIPLE_CLI_TAGS:
|
|
|
|
if len(self.options.tags) > 1:
|
2017-03-23 01:50:28 +00:00
|
|
|
display.deprecated('Specifying --tags multiple times on the command line currently uses the last specified value. '
|
|
|
|
'In 2.4, values will be merged instead. Set merge_multiple_cli_tags=True in ansible.cfg to get this behavior now.',
|
|
|
|
version=2.5, removed=False)
|
2016-09-29 21:14:02 +00:00
|
|
|
self.options.tags = [self.options.tags[-1]]
|
|
|
|
|
|
|
|
tags = set()
|
|
|
|
for tag_set in self.options.tags:
|
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
tags.add(tag.strip())
|
|
|
|
self.options.tags = list(tags)
|
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
# process skip_tags
|
2016-09-29 21:14:02 +00:00
|
|
|
if hasattr(self.options, 'skip_tags') and self.options.skip_tags:
|
|
|
|
if not C.MERGE_MULTIPLE_CLI_TAGS:
|
|
|
|
if len(self.options.skip_tags) > 1:
|
2017-03-23 01:50:28 +00:00
|
|
|
display.deprecated('Specifying --skip-tags multiple times on the command line currently uses the last specified value. '
|
|
|
|
'In 2.4, values will be merged instead. Set merge_multiple_cli_tags=True in ansible.cfg to get this behavior now.',
|
|
|
|
version=2.5, removed=False)
|
2016-09-29 21:14:02 +00:00
|
|
|
self.options.skip_tags = [self.options.skip_tags[-1]]
|
|
|
|
|
|
|
|
skip_tags = set()
|
|
|
|
for tag_set in self.options.skip_tags:
|
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
skip_tags.add(tag.strip())
|
|
|
|
self.options.skip_tags = list(skip_tags)
|
|
|
|
|
2017-10-25 23:55:48 +00:00
|
|
|
# process inventory options except for CLIs that require their own processing
|
|
|
|
if hasattr(self.options, 'inventory') and not self.SKIP_INVENTORY_DEFAULTS:
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
if self.options.inventory:
|
|
|
|
|
|
|
|
# should always be list
|
|
|
|
if isinstance(self.options.inventory, string_types):
|
|
|
|
self.options.inventory = [self.options.inventory]
|
|
|
|
|
|
|
|
# Ensure full paths when needed
|
2017-10-03 18:54:25 +00:00
|
|
|
self.options.inventory = [unfrackpath(opt, follow=False) if ',' not in opt else opt for opt in self.options.inventory]
|
2017-05-23 21:16:49 +00:00
|
|
|
else:
|
2017-09-06 18:04:17 +00:00
|
|
|
self.options.inventory = C.DEFAULT_HOST_LIST
|
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])
|
|
|
|
except:
|
|
|
|
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
|
|
|
|
def _play_prereqs(options):
|
|
|
|
|
|
|
|
# all needs loader
|
|
|
|
loader = DataLoader()
|
|
|
|
|
2017-10-31 19:41:30 +00:00
|
|
|
basedir = getattr(options, 'basedir', False)
|
|
|
|
if basedir:
|
|
|
|
loader.set_basedir(basedir)
|
|
|
|
|
2017-08-28 14:13:14 +00:00
|
|
|
vault_ids = options.vault_ids
|
|
|
|
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,
|
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=options.vault_password_files,
|
2017-09-19 21:39:51 +00:00
|
|
|
ask_vault_pass=options.ask_vault_pass,
|
|
|
|
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)
|
|
|
|
inventory = InventoryManager(loader=loader, sources=options.inventory)
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
|
|
|
|
# load vars from cli options
|
|
|
|
variable_manager.extra_vars = load_extra_vars(loader=loader, options=options)
|
|
|
|
variable_manager.options_vars = load_options_vars(options, CLI.version_info(gitinfo=False))
|
|
|
|
|
|
|
|
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
|
|
|
|
display.warning("provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'")
|
|
|
|
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
|