2018-12-18 02:10:59 +00:00
|
|
|
# Copyright: (c) 2012-2014, Michael DeHaan <michael.dehaan@gmail.com>
|
|
|
|
# Copyright: (c) 2016, Toshio Kuratomi <tkuratomi@ansible.com>
|
|
|
|
# Copyright: (c) 2018, Ansible Project
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2014-11-14 22:14:08 +00:00
|
|
|
|
|
|
|
# Make coding more python3-ish
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
import getpass
|
2014-11-14 22:14:08 +00:00
|
|
|
import os
|
2018-12-19 08:28:33 +00:00
|
|
|
import os.path
|
2017-06-02 11:14:11 +00:00
|
|
|
import re
|
2018-12-19 08:28:33 +00:00
|
|
|
import subprocess
|
2015-05-01 02:54:38 +00:00
|
|
|
import sys
|
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
|
|
|
|
|
|
|
from ansible import constants as C
|
2018-12-18 02:10:59 +00:00
|
|
|
from ansible import context
|
2018-12-20 18:07:49 +00:00
|
|
|
from ansible.cli.arguments import optparse_helpers as opt_help
|
2017-08-15 15:01:46 +00:00
|
|
|
from ansible.errors import AnsibleOptionsError, AnsibleError
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.inventory.manager import InventoryManager
|
|
|
|
from ansible.module_utils.six import with_metaclass, string_types
|
2016-09-07 05:54:17 +00:00
|
|
|
from ansible.module_utils._text import to_bytes, to_text
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.parsing.dataloader import DataLoader
|
2017-06-02 11:14:11 +00:00
|
|
|
from ansible.release import __version__
|
2018-11-20 23:06:51 +00:00
|
|
|
from ansible.utils.display import Display
|
2017-03-01 11:43:48 +00:00
|
|
|
from ansible.utils.path import unfrackpath
|
2017-05-23 21:16:49 +00:00
|
|
|
from ansible.vars.manager import VariableManager
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
from ansible.parsing.vault import PromptVaultSecret, get_file_vault_secret
|
2015-11-10 19:40:55 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
|
2018-11-20 23:06:51 +00:00
|
|
|
display = Display()
|
2015-11-10 19:40:55 +00:00
|
|
|
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
class CLI(with_metaclass(ABCMeta, object)):
|
2015-04-27 11:31:41 +00:00
|
|
|
''' code behind bin/ansible* programs '''
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2018-12-18 21:03:22 +00:00
|
|
|
VALID_ACTIONS = frozenset()
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-05-01 02:54:38 +00:00
|
|
|
_ITALIC = re.compile(r"I\(([^)]+)\)")
|
2017-06-02 11:14:11 +00:00
|
|
|
_BOLD = re.compile(r"B\(([^)]+)\)")
|
2015-05-01 02:54:38 +00:00
|
|
|
_MODULE = re.compile(r"M\(([^)]+)\)")
|
2017-06-02 11:14:11 +00:00
|
|
|
_URL = re.compile(r"U\(([^)]+)\)")
|
|
|
|
_CONST = re.compile(r"C\(([^)]+)\)")
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2017-06-02 11:14:11 +00:00
|
|
|
PAGER = 'less'
|
2017-01-27 21:04:59 +00:00
|
|
|
|
|
|
|
# -F (quit-if-one-screen) -R (allow raw ansi control chars)
|
|
|
|
# -S (chop long lines) -X (disable termcap init and de-init)
|
|
|
|
LESS_OPTS = 'FRSX'
|
2017-10-25 23:55:48 +00:00
|
|
|
SKIP_INVENTORY_DEFAULTS = False
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2015-12-10 13:04:06 +00:00
|
|
|
def __init__(self, args, callback=None):
|
2015-04-27 11:31:41 +00:00
|
|
|
"""
|
|
|
|
Base init method for all command line programs
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.args = args
|
|
|
|
self.parser = None
|
|
|
|
self.action = None
|
2015-12-10 13:04:06 +00:00
|
|
|
self.callback = callback
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
def set_action(self):
|
|
|
|
"""
|
|
|
|
Get the action the user wants to execute from the sys argv list.
|
|
|
|
"""
|
2016-09-14 18:49:54 +00:00
|
|
|
for i in range(0, len(self.args)):
|
2015-04-27 11:31:41 +00:00
|
|
|
arg = self.args[i]
|
|
|
|
if arg in self.VALID_ACTIONS:
|
|
|
|
self.action = arg
|
|
|
|
del self.args[i]
|
|
|
|
break
|
|
|
|
|
|
|
|
if not self.action:
|
2016-09-14 18:49:54 +00:00
|
|
|
# if we're asked for help or version, we don't need an action.
|
|
|
|
# have to use a special purpose Option Parser to figure that out as
|
|
|
|
# the standard OptionParser throws an error for unknown options and
|
|
|
|
# without knowing action, we only know of a subset of the options
|
|
|
|
# that could be legal for this command
|
2018-12-19 08:28:33 +00:00
|
|
|
tmp_parser = opt_help.InvalidOptsParser(self.parser)
|
2016-09-14 18:49:54 +00:00
|
|
|
tmp_options, tmp_args = tmp_parser.parse_args(self.args)
|
2016-05-31 13:30:50 +00:00
|
|
|
if not(hasattr(tmp_options, 'help') and tmp_options.help) or (hasattr(tmp_options, 'version') and tmp_options.version):
|
|
|
|
raise AnsibleOptionsError("Missing required action")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
def execute(self):
|
|
|
|
"""
|
|
|
|
Actually runs a child defined method using the execute_<action> pattern
|
|
|
|
"""
|
|
|
|
fn = getattr(self, "execute_%s" % self.action)
|
|
|
|
fn()
|
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
@abstractmethod
|
2015-04-27 11:31:41 +00:00
|
|
|
def run(self):
|
2016-09-29 21:14:02 +00:00
|
|
|
"""Run the ansible command
|
|
|
|
|
|
|
|
Subclasses must implement this method. It does the actual work of
|
|
|
|
running an Ansible command.
|
|
|
|
"""
|
2018-12-18 02:10:59 +00:00
|
|
|
self.parse()
|
2015-07-04 14:23:30 +00:00
|
|
|
|
2017-08-04 13:25:08 +00:00
|
|
|
display.vv(to_text(self.parser.get_version()))
|
2017-05-24 18:45:35 +00:00
|
|
|
|
|
|
|
if C.CONFIG_FILE:
|
|
|
|
display.v(u"Using %s as config file" % to_text(C.CONFIG_FILE))
|
|
|
|
else:
|
|
|
|
display.v(u"No config file found; using defaults")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2017-09-14 20:56:52 +00:00
|
|
|
# warn about deprecated config options
|
2017-08-20 15:20:30 +00:00
|
|
|
for deprecated in C.config.DEPRECATED:
|
|
|
|
name = deprecated[0]
|
|
|
|
why = deprecated[1]['why']
|
2018-01-10 00:07:06 +00:00
|
|
|
if 'alternatives' in deprecated[1]:
|
|
|
|
alt = ', use %s instead' % deprecated[1]['alternatives']
|
2017-08-20 15:20:30 +00:00
|
|
|
else:
|
|
|
|
alt = ''
|
|
|
|
ver = deprecated[1]['version']
|
|
|
|
display.deprecated("%s option, %s %s" % (name, why, alt), version=ver)
|
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
@staticmethod
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
def split_vault_id(vault_id):
|
|
|
|
# return (before_@, after_@)
|
|
|
|
# if no @, return whole string as after_
|
|
|
|
if '@' not in vault_id:
|
|
|
|
return (None, vault_id)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
parts = vault_id.split('@', 1)
|
|
|
|
ret = tuple(parts)
|
|
|
|
return ret
|
2016-10-31 16:56:18 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
@staticmethod
|
2017-08-15 15:01:46 +00:00
|
|
|
def build_vault_ids(vault_ids, vault_password_files=None,
|
2017-09-19 21:39:51 +00:00
|
|
|
ask_vault_pass=None, create_new_password=None,
|
|
|
|
auto_prompt=True):
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_password_files = vault_password_files or []
|
|
|
|
vault_ids = vault_ids or []
|
2015-04-27 11:31:41 +00:00
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# convert vault_password_files into vault_ids slugs
|
|
|
|
for password_file in vault_password_files:
|
|
|
|
id_slug = u'%s@%s' % (C.DEFAULT_VAULT_IDENTITY, password_file)
|
2016-10-31 16:56:18 +00:00
|
|
|
|
2018-12-14 09:42:58 +00:00
|
|
|
# note this makes --vault-id higher precedence than --vault-password-file
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# if we want to intertwingle them in order probably need a cli callback to populate vault_ids
|
|
|
|
# used by --vault-id and --vault-password-file
|
|
|
|
vault_ids.append(id_slug)
|
2016-10-31 16:56:18 +00:00
|
|
|
|
2017-08-15 15:01:46 +00:00
|
|
|
# if an action needs an encrypt password (create_new_password=True) and we dont
|
|
|
|
# have other secrets setup, then automatically add a password prompt as well.
|
2017-11-15 19:01:32 +00:00
|
|
|
# prompts cant/shouldnt work without a tty, so dont add prompt secrets
|
|
|
|
if ask_vault_pass or (not vault_ids and auto_prompt):
|
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
id_slug = u'%s@%s' % (C.DEFAULT_VAULT_IDENTITY, u'prompt_ask_vault_pass')
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_ids.append(id_slug)
|
|
|
|
|
|
|
|
return vault_ids
|
|
|
|
|
|
|
|
# TODO: remove the now unused args
|
2016-10-31 16:56:18 +00:00
|
|
|
@staticmethod
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
def setup_vault_secrets(loader, vault_ids, vault_password_files=None,
|
2017-09-19 21:39:51 +00:00
|
|
|
ask_vault_pass=None, create_new_password=False,
|
|
|
|
auto_prompt=True):
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
# list of tuples
|
|
|
|
vault_secrets = []
|
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
# Depending on the vault_id value (including how --ask-vault-pass / --vault-password-file create a vault_id)
|
|
|
|
# we need to show different prompts. This is for compat with older Towers that expect a
|
|
|
|
# certain vault password prompt format, so 'promp_ask_vault_pass' vault_id gets the old format.
|
|
|
|
prompt_formats = {}
|
2017-08-01 22:07:33 +00:00
|
|
|
|
2017-08-15 15:56:17 +00:00
|
|
|
# If there are configured default vault identities, they are considered 'first'
|
|
|
|
# so we prepend them to vault_ids (from cli) here
|
|
|
|
|
2017-08-01 22:07:33 +00:00
|
|
|
vault_password_files = vault_password_files or []
|
|
|
|
if C.DEFAULT_VAULT_PASSWORD_FILE:
|
|
|
|
vault_password_files.append(C.DEFAULT_VAULT_PASSWORD_FILE)
|
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
if create_new_password:
|
2017-08-01 20:39:54 +00:00
|
|
|
prompt_formats['prompt'] = ['New vault password (%(vault_id)s): ',
|
2018-12-04 11:04:29 +00:00
|
|
|
'Confirm new vault password (%(vault_id)s): ']
|
2017-08-10 13:34:16 +00:00
|
|
|
# 2.3 format prompts for --ask-vault-pass
|
|
|
|
prompt_formats['prompt_ask_vault_pass'] = ['New Vault password: ',
|
|
|
|
'Confirm New Vault password: ']
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
else:
|
2017-08-01 20:39:54 +00:00
|
|
|
prompt_formats['prompt'] = ['Vault password (%(vault_id)s): ']
|
|
|
|
# The format when we use just --ask-vault-pass needs to match 'Vault password:\s*?$'
|
|
|
|
prompt_formats['prompt_ask_vault_pass'] = ['Vault password: ']
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
|
|
|
vault_ids = CLI.build_vault_ids(vault_ids,
|
|
|
|
vault_password_files,
|
2017-08-15 17:09:24 +00:00
|
|
|
ask_vault_pass,
|
2017-09-19 21:39:51 +00:00
|
|
|
create_new_password,
|
|
|
|
auto_prompt=auto_prompt)
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
2017-08-08 20:10:03 +00:00
|
|
|
for vault_id_slug in vault_ids:
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_id_name, vault_id_value = CLI.split_vault_id(vault_id_slug)
|
2017-08-01 20:39:54 +00:00
|
|
|
if vault_id_value in ['prompt', 'prompt_ask_vault_pass']:
|
2017-08-15 17:09:24 +00:00
|
|
|
|
2017-08-01 20:39:54 +00:00
|
|
|
# --vault-id some_name@prompt_ask_vault_pass --vault-id other_name@prompt_ask_vault_pass will be a little
|
|
|
|
# confusing since it will use the old format without the vault id in the prompt
|
2017-08-15 15:01:46 +00:00
|
|
|
built_vault_id = vault_id_name or C.DEFAULT_VAULT_IDENTITY
|
|
|
|
|
|
|
|
# choose the prompt based on --vault-id=prompt or --ask-vault-pass. --ask-vault-pass
|
|
|
|
# always gets the old format for Tower compatibility.
|
|
|
|
# ie, we used --ask-vault-pass, so we need to use the old vault password prompt
|
|
|
|
# format since Tower needs to match on that format.
|
|
|
|
prompted_vault_secret = PromptVaultSecret(prompt_formats=prompt_formats[vault_id_value],
|
|
|
|
vault_id=built_vault_id)
|
|
|
|
|
|
|
|
# a empty or invalid password from the prompt will warn and continue to the next
|
2018-12-14 09:42:58 +00:00
|
|
|
# without erroring globally
|
2017-08-15 15:01:46 +00:00
|
|
|
try:
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
prompted_vault_secret.load()
|
2017-08-15 15:01:46 +00:00
|
|
|
except AnsibleError as exc:
|
|
|
|
display.warning('Error in vault password prompt (%s): %s' % (vault_id_name, exc))
|
|
|
|
raise
|
|
|
|
|
|
|
|
vault_secrets.append((built_vault_id, prompted_vault_secret))
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
|
|
|
|
# update loader with new secrets incrementally, so we can load a vault password
|
|
|
|
# that is encrypted with a vault secret provided earlier
|
|
|
|
loader.set_vault_secrets(vault_secrets)
|
|
|
|
continue
|
|
|
|
|
|
|
|
# assuming anything else is a password file
|
|
|
|
display.vvvvv('Reading vault password file: %s' % vault_id_value)
|
|
|
|
# read vault_pass from a file
|
|
|
|
file_vault_secret = get_file_vault_secret(filename=vault_id_value,
|
2017-10-13 19:23:08 +00:00
|
|
|
vault_id=vault_id_name,
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
loader=loader)
|
2017-08-15 15:01:46 +00:00
|
|
|
|
|
|
|
# an invalid password file will error globally
|
|
|
|
try:
|
|
|
|
file_vault_secret.load()
|
|
|
|
except AnsibleError as exc:
|
2019-01-17 17:18:01 +00:00
|
|
|
display.warning('Error in vault password file loading (%s): %s' % (vault_id_name, to_text(exc)))
|
2017-08-15 15:01:46 +00:00
|
|
|
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
|
|
|
|
2018-12-20 04:45:47 +00:00
|
|
|
@staticmethod
|
|
|
|
def ask_passwords():
|
2015-04-30 22:43:53 +00:00
|
|
|
''' prompt for connection and become passwords if needed '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
op = context.CLIARGS
|
2015-04-27 11:31:41 +00:00
|
|
|
sshpass = None
|
|
|
|
becomepass = None
|
|
|
|
become_prompt = ''
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
become_prompt_method = "BECOME" if C.AGNOSTIC_BECOME_PROMPT else op['become_method'].upper()
|
2018-01-12 16:28:46 +00:00
|
|
|
|
2015-07-01 09:21:46 +00:00
|
|
|
try:
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['ask_pass']:
|
2015-07-01 09:21:46 +00:00
|
|
|
sshpass = getpass.getpass(prompt="SSH password: ")
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt = "%s password[defaults to SSH password]: " % become_prompt_method
|
2015-07-01 09:21:46 +00:00
|
|
|
if sshpass:
|
2018-07-11 14:24:45 +00:00
|
|
|
sshpass = to_bytes(sshpass, errors='strict', nonstring='simplerepr')
|
2015-07-01 09:21:46 +00:00
|
|
|
else:
|
2018-01-12 16:28:46 +00:00
|
|
|
become_prompt = "%s password: " % become_prompt_method
|
2015-07-01 09:21:46 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['become_ask_pass']:
|
2015-07-01 09:21:46 +00:00
|
|
|
becomepass = getpass.getpass(prompt=become_prompt)
|
2018-12-18 02:10:59 +00:00
|
|
|
if op['ask_pass'] and becomepass == '':
|
2015-07-01 09:21:46 +00:00
|
|
|
becomepass = sshpass
|
|
|
|
if becomepass:
|
2018-07-11 14:24:45 +00:00
|
|
|
becomepass = to_bytes(becomepass)
|
2015-07-01 09:21:46 +00:00
|
|
|
except EOFError:
|
|
|
|
pass
|
2015-04-27 11:31:41 +00:00
|
|
|
|
|
|
|
return (sshpass, becomepass)
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
@staticmethod
|
|
|
|
def normalize_become_options(options):
|
|
|
|
''' this keeps backwards compatibility with sudo/su command line options '''
|
|
|
|
if not options.become_ask_pass:
|
|
|
|
options.become_ask_pass = options.ask_sudo_pass or options.ask_su_pass or C.DEFAULT_BECOME_ASK_PASS
|
|
|
|
if not options.become_user:
|
|
|
|
options.become_user = options.sudo_user or options.su_user or C.DEFAULT_BECOME_USER
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2017-06-13 14:46:09 +00:00
|
|
|
def _dep(which):
|
2018-08-23 18:22:54 +00:00
|
|
|
display.deprecated('The %s command line option has been deprecated in favor of the "become" command line arguments' % which, '2.9')
|
2017-06-13 14:46:09 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.become:
|
2014-11-14 22:14:08 +00:00
|
|
|
pass
|
2018-12-18 02:10:59 +00:00
|
|
|
elif options.sudo:
|
|
|
|
options.become = True
|
|
|
|
options.become_method = 'sudo'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('sudo')
|
2018-12-18 02:10:59 +00:00
|
|
|
elif options.su:
|
|
|
|
options.become = True
|
|
|
|
options.become_method = 'su'
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('su')
|
|
|
|
|
|
|
|
# other deprecations:
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.ask_sudo_pass or options.sudo_user:
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('sudo')
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.ask_su_pass or options.su_user:
|
2017-06-13 14:46:09 +00:00
|
|
|
_dep('su')
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
return options
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
def validate_conflicts(self, op, vault_opts=False, runas_opts=False, fork_opts=False, vault_rekey_opts=False):
|
|
|
|
''' check for conflicting options '''
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if vault_opts:
|
|
|
|
# Check for vault related conflicts
|
2018-12-18 02:10:59 +00:00
|
|
|
if op.ask_vault_pass and op.vault_password_files:
|
2015-06-09 21:24:06 +00:00
|
|
|
self.parser.error("--ask-vault-pass and --vault-password-file are mutually exclusive")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2018-01-22 22:12:10 +00:00
|
|
|
if vault_rekey_opts:
|
2018-12-18 02:10:59 +00:00
|
|
|
if op.new_vault_id and op.new_vault_password_file:
|
2018-01-22 22:12:10 +00:00
|
|
|
self.parser.error("--new-vault-password-file and --new-vault-id are mutually exclusive")
|
|
|
|
|
2015-06-09 21:24:06 +00:00
|
|
|
if runas_opts:
|
|
|
|
# Check for privilege escalation conflicts
|
2017-03-22 02:19:40 +00:00
|
|
|
if ((op.su or op.su_user) and (op.sudo or op.sudo_user) or
|
|
|
|
(op.su or op.su_user) and (op.become or op.become_user) or
|
|
|
|
(op.sudo or op.sudo_user) and (op.become or op.become_user)):
|
2015-06-09 21:24:06 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
self.parser.error("Sudo arguments ('--sudo', '--sudo-user', and '--ask-sudo-pass')"
|
|
|
|
" and su arguments ('--su', '--su-user', and '--ask-su-pass')"
|
|
|
|
" and become arguments ('--become', '--become-user', and"
|
|
|
|
" '--ask-become-pass') are exclusive of each other")
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2015-08-02 08:40:42 +00:00
|
|
|
if fork_opts:
|
|
|
|
if op.forks < 1:
|
|
|
|
self.parser.error("The number of processes (--forks) must be >= 1")
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
return op
|
|
|
|
|
|
|
|
@abstractmethod
|
2018-12-19 08:28:33 +00:00
|
|
|
def init_parser(self, usage="", desc=None, epilog=None):
|
2018-12-18 02:10:59 +00:00
|
|
|
"""
|
|
|
|
Create an options parser for most ansible scripts
|
2015-05-01 01:22:23 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
Subclasses need to implement this method. They will usually call the base class's
|
|
|
|
init_parser to create a basic version and then add their own options on top of that.
|
2015-06-09 21:24:06 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
An implementation will look something like this::
|
2017-12-07 04:50:51 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
def init_parser(self):
|
2018-12-20 04:45:47 +00:00
|
|
|
super(MyCLI, self).init_parser(usage="My Ansible CLI", inventory_opts=True)
|
2018-12-19 08:28:33 +00:00
|
|
|
ansible.arguments.optparse_helpers.add_runas_options(self.parser)
|
2018-12-18 02:10:59 +00:00
|
|
|
self.parser.add_option('--my-option', dest='my_option', action='store')
|
|
|
|
"""
|
2018-12-19 08:28:33 +00:00
|
|
|
self.parser = opt_help.create_base_parser(usage=usage, desc=desc, epilog=epilog)
|
2015-04-27 11:31:41 +00:00
|
|
|
|
2016-09-29 21:14:02 +00:00
|
|
|
@abstractmethod
|
2018-12-18 02:10:59 +00:00
|
|
|
def post_process_args(self, options, args):
|
|
|
|
"""Process the command line args
|
|
|
|
|
|
|
|
Subclasses need to implement this method. This method validates and transforms the command
|
|
|
|
line arguments. It can be used to check whether conflicting values were given, whether filenames
|
|
|
|
exist, etc.
|
|
|
|
|
|
|
|
An implementation will look something like this::
|
|
|
|
|
|
|
|
def post_process_args(self, options, args):
|
|
|
|
options, args = super(MyCLI, self).post_process_args(options, args)
|
|
|
|
if options.addition and options.subtraction:
|
|
|
|
raise AnsibleOptionsError('Only one of --addition and --subtraction can be specified')
|
|
|
|
if isinstance(options.listofhosts, string_types):
|
|
|
|
options.listofhosts = string_types.split(',')
|
|
|
|
return options, args
|
2016-09-29 21:14:02 +00:00
|
|
|
"""
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# process tags
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'tags') and not options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
# optparse defaults does not do what's expected
|
2018-12-18 02:10:59 +00:00
|
|
|
options.tags = ['all']
|
|
|
|
if hasattr(options, 'tags') and options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
tags = set()
|
2018-12-18 02:10:59 +00:00
|
|
|
for tag_set in options.tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
tags.add(tag.strip())
|
2018-12-18 02:10:59 +00:00
|
|
|
options.tags = list(tags)
|
2016-09-29 21:14:02 +00:00
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
# process skip_tags
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'skip_tags') and options.skip_tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
skip_tags = set()
|
2018-12-18 02:10:59 +00:00
|
|
|
for tag_set in options.skip_tags:
|
2016-09-29 21:14:02 +00:00
|
|
|
for tag in tag_set.split(u','):
|
|
|
|
skip_tags.add(tag.strip())
|
2018-12-18 02:10:59 +00:00
|
|
|
options.skip_tags = list(skip_tags)
|
2016-09-29 21:14:02 +00:00
|
|
|
|
2017-10-25 23:55:48 +00:00
|
|
|
# process inventory options except for CLIs that require their own processing
|
2018-12-18 02:10:59 +00:00
|
|
|
if hasattr(options, 'inventory') and not self.SKIP_INVENTORY_DEFAULTS:
|
2017-05-23 21:16:49 +00:00
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
if options.inventory:
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# should always be list
|
2018-12-18 02:10:59 +00:00
|
|
|
if isinstance(options.inventory, string_types):
|
|
|
|
options.inventory = [options.inventory]
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# Ensure full paths when needed
|
2018-12-18 02:10:59 +00:00
|
|
|
options.inventory = [unfrackpath(opt, follow=False) if ',' not in opt else opt for opt in options.inventory]
|
2017-05-23 21:16:49 +00:00
|
|
|
else:
|
2018-12-18 02:10:59 +00:00
|
|
|
options.inventory = C.DEFAULT_HOST_LIST
|
|
|
|
|
|
|
|
return options, args
|
|
|
|
|
|
|
|
def parse(self):
|
|
|
|
"""Parse the command line args
|
|
|
|
|
|
|
|
This method parses the command line arguments. It uses the parser
|
|
|
|
stored in the self.parser attribute and saves the args and options in
|
|
|
|
context.CLIARGS.
|
|
|
|
|
|
|
|
Subclasses need to implement two helper methods, init_parser() and post_process_args() which
|
|
|
|
are called from this function before and after parsing the arguments.
|
|
|
|
"""
|
|
|
|
self.init_parser()
|
|
|
|
options, args = self.parser.parse_args(self.args[1:])
|
|
|
|
options, args = self.post_process_args(options, args)
|
|
|
|
options.args = args
|
|
|
|
context._init_global_context(options)
|
2017-05-23 21:16:49 +00:00
|
|
|
|
2015-04-27 11:31:41 +00:00
|
|
|
@staticmethod
|
|
|
|
def version_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
|
2018-12-19 08:28:33 +00:00
|
|
|
ansible_version_string = opt_help.version()
|
2015-04-27 11:31:41 +00:00
|
|
|
else:
|
|
|
|
ansible_version_string = __version__
|
|
|
|
ansible_version = ansible_version_string.split()[0]
|
|
|
|
ansible_versions = ansible_version.split('.')
|
|
|
|
for counter in range(len(ansible_versions)):
|
|
|
|
if ansible_versions[counter] == "":
|
|
|
|
ansible_versions[counter] = 0
|
|
|
|
try:
|
|
|
|
ansible_versions[counter] = int(ansible_versions[counter])
|
2018-06-29 23:45:38 +00:00
|
|
|
except Exception:
|
2015-04-27 11:31:41 +00:00
|
|
|
pass
|
|
|
|
if len(ansible_versions) < 3:
|
|
|
|
for counter in range(len(ansible_versions), 3):
|
|
|
|
ansible_versions.append(0)
|
2017-06-02 11:14:11 +00:00
|
|
|
return {'string': ansible_version_string.strip(),
|
|
|
|
'full': ansible_version,
|
|
|
|
'major': ansible_versions[0],
|
|
|
|
'minor': ansible_versions[1],
|
|
|
|
'revision': ansible_versions[2]}
|
2014-11-14 22:14:08 +00:00
|
|
|
|
2018-12-20 04:45:47 +00:00
|
|
|
@staticmethod
|
|
|
|
def pager(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:
|
2018-12-20 04:45:47 +00:00
|
|
|
CLI.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:
|
2018-12-20 04:45:47 +00:00
|
|
|
CLI.pager_pipe(text, 'less')
|
2016-09-09 13:30:37 +00:00
|
|
|
else:
|
2017-06-15 14:45:01 +00:00
|
|
|
display.display(text, screen_only=True)
|
2015-05-01 02:54:38 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def pager_pipe(text, cmd):
|
|
|
|
''' pipe text through a pager '''
|
|
|
|
if 'LESS' not in os.environ:
|
2015-05-12 16:26:20 +00:00
|
|
|
os.environ['LESS'] = CLI.LESS_OPTS
|
2015-05-01 02:54:38 +00:00
|
|
|
try:
|
|
|
|
cmd = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=sys.stdout)
|
2016-01-28 18:50:20 +00:00
|
|
|
cmd.communicate(input=to_bytes(text))
|
2015-05-01 02:54:38 +00:00
|
|
|
except IOError:
|
|
|
|
pass
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
|
|
|
|
|
|
|
@classmethod
|
2015-10-09 04:46:31 +00:00
|
|
|
def tty_ify(cls, text):
|
2015-05-01 02:54:38 +00:00
|
|
|
|
2015-10-09 04:46:31 +00:00
|
|
|
t = cls._ITALIC.sub("`" + r"\1" + "'", text) # I(word) => `word'
|
|
|
|
t = cls._BOLD.sub("*" + r"\1" + "*", t) # B(word) => *word*
|
|
|
|
t = cls._MODULE.sub("[" + r"\1" + "]", t) # M(word) => [word]
|
|
|
|
t = cls._URL.sub(r"\1", t) # U(word) => word
|
|
|
|
t = cls._CONST.sub("`" + r"\1" + "'", t) # C(word) => `word'
|
2015-05-01 02:54:38 +00:00
|
|
|
|
|
|
|
return t
|
2015-07-11 18:24:45 +00:00
|
|
|
|
2017-05-23 21:16:49 +00:00
|
|
|
@staticmethod
|
2018-12-18 02:10:59 +00:00
|
|
|
def _play_prereqs():
|
|
|
|
options = context.CLIARGS
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# all needs loader
|
|
|
|
loader = DataLoader()
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
basedir = options.get('basedir', False)
|
2017-10-31 19:41:30 +00:00
|
|
|
if basedir:
|
|
|
|
loader.set_basedir(basedir)
|
|
|
|
|
2018-12-18 02:10:59 +00:00
|
|
|
vault_ids = list(options['vault_ids'])
|
2017-08-28 14:13:14 +00:00
|
|
|
default_vault_ids = C.DEFAULT_VAULT_IDENTITY_LIST
|
|
|
|
vault_ids = default_vault_ids + vault_ids
|
|
|
|
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
vault_secrets = CLI.setup_vault_secrets(loader,
|
2017-08-28 14:13:14 +00:00
|
|
|
vault_ids=vault_ids,
|
2018-12-18 02:10:59 +00:00
|
|
|
vault_password_files=list(options['vault_password_files']),
|
|
|
|
ask_vault_pass=options['ask_vault_pass'],
|
2017-09-19 21:39:51 +00:00
|
|
|
auto_prompt=False)
|
Support multiple vault passwords (#22756)
Fixes #13243
** Add --vault-id to name/identify multiple vault passwords
Use --vault-id to indicate id and path/type
--vault-id=prompt # prompt for default vault id password
--vault-id=myorg@prompt # prompt for a vault_id named 'myorg'
--vault-id=a_password_file # load ./a_password_file for default id
--vault-id=myorg@a_password_file # load file for 'myorg' vault id
vault_id's are created implicitly for existing --vault-password-file
and --ask-vault-pass options.
Vault ids are just for UX purposes and bookkeeping. Only the vault
payload and the password bytestring is needed to decrypt a
vault blob.
Replace passing password around everywhere with
a VaultSecrets object.
If we specify a vault_id, mention that in password prompts
Specifying multiple -vault-password-files will
now try each until one works
** Rev vault format in a backwards compatible way
The 1.2 vault format adds the vault_id to the header line
of the vault text. This is backwards compatible with older
versions of ansible. Old versions will just ignore it and
treat it as the default (and only) vault id.
Note: only 2.4+ supports multiple vault passwords, so while
earlier ansible versions can read the vault-1.2 format, it
does not make them magically support multiple vault passwords.
use 1.1 format for 'default' vault_id
Vaulted items that need to include a vault_id will be
written in 1.2 format.
If we set a new DEFAULT_VAULT_IDENTITY, then the default will
use version 1.2
vault will only use a vault_id if one is specified. So if none
is specified and C.DEFAULT_VAULT_IDENTITY is 'default'
we use the old format.
** Changes/refactors needed to implement multiple vault passwords
raise exceptions on decrypt fail, check vault id early
split out parsing the vault plaintext envelope (with the
sha/original plaintext) to _split_plaintext_envelope()
some cli fixups for specifying multiple paths in
the unfrack_paths optparse callback
fix py3 dict.keys() 'dict_keys object is not indexable' error
pluralize cli.options.vault_password_file -> vault_password_files
pluralize cli.options.new_vault_password_file -> new_vault_password_files
pluralize cli.options.vault_id -> cli.options.vault_ids
** Add a config option (vault_id_match) to force vault id matching.
With 'vault_id_match=True' and an ansible
vault that provides a vault_id, then decryption will require
that a matching vault_id is required. (via
--vault-id=my_vault_id@password_file, for ex).
In other words, if the config option is true, then only
the vault secrets with matching vault ids are candidates for
decrypting a vault. If option is false (the default), then
all of the provided vault secrets will be selected.
If a user doesn't want all vault secrets to be tried to
decrypt any vault content, they can enable this option.
Note: The vault id used for the match is not encrypted or
cryptographically signed. It is just a label/id/nickname used
for referencing a specific vault secret.
2017-07-28 19:20:58 +00:00
|
|
|
loader.set_vault_secrets(vault_secrets)
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# create the inventory, and filter it based on the subset specified (if any)
|
2018-12-18 02:10:59 +00:00
|
|
|
inventory = InventoryManager(loader=loader, sources=options['inventory'])
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
# create the variable manager, which will be shared throughout
|
|
|
|
# the code, ensuring a consistent view of global variables
|
2019-01-30 21:25:36 +00:00
|
|
|
variable_manager = VariableManager(loader=loader, inventory=inventory, version_info=CLI.version_info(gitinfo=False))
|
2017-05-23 21:16:49 +00:00
|
|
|
|
|
|
|
return loader, inventory, variable_manager
|
2017-12-15 20:43:51 +00:00
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def get_host_list(inventory, subset, pattern='all'):
|
|
|
|
|
|
|
|
no_hosts = False
|
|
|
|
if len(inventory.list_hosts()) == 0:
|
|
|
|
# Empty inventory
|
2018-11-07 16:09:32 +00:00
|
|
|
if C.LOCALHOST_WARNING and pattern not in C.LOCALHOST:
|
2018-03-24 12:59:19 +00:00
|
|
|
display.warning("provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'")
|
2017-12-15 20:43:51 +00:00
|
|
|
no_hosts = True
|
|
|
|
|
|
|
|
inventory.subset(subset)
|
|
|
|
|
|
|
|
hosts = inventory.list_hosts(pattern)
|
|
|
|
if len(hosts) == 0 and no_hosts is False:
|
|
|
|
raise AnsibleError("Specified hosts and/or --limit does not match any hosts")
|
|
|
|
|
|
|
|
return hosts
|