From c79c001bfb626eefbc1f43df44f0def0f56a5101 Mon Sep 17 00:00:00 2001 From: Ramon de la Fuente Date: Wed, 19 Mar 2014 14:35:11 +0100 Subject: [PATCH] Changed call to EDITOR to allow for parameters The EDITOR environment variable is used to create and edit files in the vault. But if the EDITOR variable contains parameters, subprocess.call() breaks. This fixes the EDITOR environment variable to be safely split into a list. It adds a dependency on shlex. --- lib/ansible/utils/vault.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/ansible/utils/vault.py b/lib/ansible/utils/vault.py index 62b082a9af4..265bf7a053e 100644 --- a/lib/ansible/utils/vault.py +++ b/lib/ansible/utils/vault.py @@ -19,6 +19,7 @@ # installs ansible and sets it up to run on cron. import os +import shlex import shutil import tempfile from io import BytesIO @@ -189,8 +190,7 @@ class VaultEditor(object): raise errors.AnsibleError("%s exists, please use 'edit' instead" % self.filename) # drop the user into vim on file - EDITOR = os.environ.get('EDITOR','vim') - call([EDITOR, self.filename]) + call(self._editor_shell_command(self.filename)) tmpdata = self.read_data(self.filename) this_vault = VaultLib(self.password) this_vault.cipher_name = self.cipher_name @@ -226,8 +226,7 @@ class VaultEditor(object): self.write_data(dec_data, tmp_path) # drop the user into vim on the tmp file - EDITOR = os.environ.get('EDITOR','vim') - call([EDITOR, tmp_path]) + call(self._editor_shell_command(tmp_path)) new_data = self.read_data(tmp_path) # create new vault @@ -299,6 +298,13 @@ class VaultEditor(object): os.remove(dest) shutil.move(src, dest) + def _editor_shell_command(self, filename): + EDITOR = os.environ.get('EDITOR','vim') + editor = shlex.split(EDITOR) + editor.append(filename) + + return editor + ######################################## # CIPHERS # ########################################