mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 22:30:22 -07:00
Fix 'vault rekey' with vault secret env var
if ANSIBLE_VAULT_PASSWORD_FILE is set, 'ansible-vault rekey myvault.yml' will fail to prompt for the new vault password file, and will use None. Fix is to split out 'ask_vault_passwords' into 'ask_vault_passwords' and 'ask_new_vault_passwords' to make the logic simpler. And then make sure new_vault_pass is always set for 'rekey', and if not, then call ask_new_vault_passwords() to set it. ask_vault_passwords() would return values for vault_pass and new vault_pass, and vault cli previously would not prompt for new_vault_pass if there was a vault_pass set via a vault password file. Fixes #18247
This commit is contained in:
parent
557f46658c
commit
309f54b709
5 changed files with 32 additions and 22 deletions
|
@ -101,21 +101,23 @@ class VaultCLI(CLI):
|
|||
if self.options.vault_password_file:
|
||||
# read vault_pass from a file
|
||||
self.vault_pass = CLI.read_vault_password_file(self.options.vault_password_file, loader)
|
||||
else:
|
||||
newpass = False
|
||||
rekey = False
|
||||
if not self.options.new_vault_password_file:
|
||||
newpass = (self.action in ['create', 'rekey', 'encrypt'])
|
||||
rekey = (self.action == 'rekey')
|
||||
self.vault_pass, self.new_vault_pass = self.ask_vault_passwords(ask_new_vault_pass=newpass, rekey=rekey)
|
||||
|
||||
if self.options.new_vault_password_file:
|
||||
# for rekey only
|
||||
self.new_vault_pass = CLI.read_vault_password_file(self.options.new_vault_password_file, loader)
|
||||
|
||||
if not self.vault_pass or self.options.ask_vault_pass:
|
||||
self.vault_pass = self.ask_vault_passwords()
|
||||
|
||||
if not self.vault_pass:
|
||||
raise AnsibleOptionsError("A password is required to use Ansible's Vault")
|
||||
|
||||
if self.action == 'rekey':
|
||||
if not self.new_vault_pass:
|
||||
self.new_vault_pass = self.ask_new_vault_passwords()
|
||||
if not self.new_vault_pass:
|
||||
raise AnsibleOptionsError("A password is required to rekey Ansible's Vault")
|
||||
|
||||
self.editor = VaultEditor(self.vault_pass)
|
||||
|
||||
self.execute()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue