Skip to content

Commit c275aec

Browse files
Zuulopenstack-gerrit
authored andcommitted
Merge "feat: add command to view passwords"
2 parents fe86f0a + ddccfb1 commit c275aec

File tree

5 files changed

+45
-0
lines changed

5 files changed

+45
-0
lines changed

doc/source/usage.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,16 @@ Environment variable: ``ANSIBLE_VAULT_PASSWORD_FILE``
4848
password from a (plain text) file, with the path to that file being read
4949
from the environment.
5050

51+
Whilst the kolla passwords file ``kolla/passwords.yml`` should remain encrypted
52+
at all times it can be useful to view the contents of this file to acquire a
53+
password for a given service.
54+
This can be done with ``ansible-vault view`` however if an absolute path is not
55+
provided it will cause the command to fail.
56+
Therefore, to make reading the contents of this file easier for administrators
57+
it is possible to use ``kayobe overcloud passwords view`` which will
58+
temporarily decrypt and display the contents of ``kolla/passwords.yml`` for the
59+
active kayobe environment.
60+
5161
Limiting Hosts
5262
--------------
5363

kayobe/cli/commands.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,6 +1579,14 @@ def take_action(self, parsed_args):
15791579
self.run_kolla_ansible_overcloud(parsed_args, "prechecks")
15801580

15811581

1582+
class OvercloudServicePasswordsView(KayobeAnsibleMixin, VaultMixin, Command):
1583+
"""View Passwords."""
1584+
1585+
def take_action(self, parsed_args):
1586+
self.app.LOG.debug("Displaying Passwords")
1587+
vault.view_passwords(parsed_args)
1588+
1589+
15821590
class OvercloudServiceReconfigure(KollaAnsibleMixin, KayobeAnsibleMixin,
15831591
VaultMixin, Command):
15841592
"""Reconfigure the overcloud services.

kayobe/vault.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,3 +172,22 @@ def update_environment(parsed_args, env):
172172

173173
if vault_password is not None:
174174
env[VAULT_PASSWORD_ENV] = vault_password
175+
176+
177+
def view_passwords(parsed_args):
178+
"""View passwords stored in the Ansible Vault.
179+
180+
:param parsed_args: Parsed command line arguments.
181+
"""
182+
env_path = utils.get_kayobe_environment_path(
183+
parsed_args.config_path, parsed_args.environment)
184+
path = env_path if env_path else parsed_args.config_path
185+
passwords_path = os.path.join(path, 'kolla', 'passwords.yml')
186+
cmd = ["ansible-vault", "view", passwords_path]
187+
cmd += ["--vault-password-file", _get_vault_password_helper()]
188+
try:
189+
utils.run_command(cmd)
190+
except subprocess.CalledProcessError as e:
191+
LOG.error("Failed to view passwords via ansible-vault "
192+
"returncode %d", e.returncode)
193+
sys.exit(e.returncode)
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
features:
3+
- |
4+
Add support for easily viewing the content of ``kolla/passwords.yml`` with
5+
the new command ``kayobe overcloud passwords view``.

setup.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ kayobe.cli=
7575
overcloud_service_deploy = kayobe.cli.commands:OvercloudServiceDeploy
7676
overcloud_service_deploy_containers = kayobe.cli.commands:OvercloudServiceDeployContainers
7777
overcloud_service_destroy = kayobe.cli.commands:OvercloudServiceDestroy
78+
overcloud_service_passwords_view = kayobe.cli.commands:OvercloudServicePasswordsView
7879
overcloud_service_prechecks = kayobe.cli.commands:OvercloudServicePrechecks
7980
overcloud_service_reconfigure = kayobe.cli.commands:OvercloudServiceReconfigure
8081
overcloud_service_stop = kayobe.cli.commands:OvercloudServiceStop
@@ -193,6 +194,8 @@ kayobe.cli.overcloud_service_upgrade =
193194
hooks = kayobe.cli.commands:HookDispatcher
194195
kayobe.cli.overcloud_swift_rings_generate =
195196
hooks = kayobe.cli.commands:HookDispatcher
197+
kayobe.cli.overcloud_passwords_view =
198+
hooks = kayobe.cli.commands:HookDispatcher
196199
kayobe.cli.physical_network_configure =
197200
hooks = kayobe.cli.commands:HookDispatcher
198201
kayobe.cli.playbook_run =

0 commit comments

Comments
 (0)