From 249caac0d30c21e47d756c4484283ca8e9f90c12 Mon Sep 17 00:00:00 2001 From: Peter Sprygada Date: Sun, 13 Mar 2016 16:01:58 -0700 Subject: [PATCH] feature to allow prompts to be configured at instatiation This commit adds a new feature to allow implementations of shell to specify the command prompt regexp to be used. It allows adds a new kwarg at instantiation to kick the remote device with a carriage return. By default the kickstart flag is true but can be disabled by passing kickstart=False. --- lib/ansible/module_utils/shell.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/ansible/module_utils/shell.py b/lib/ansible/module_utils/shell.py index 2e49f279b5..ceb7490e6e 100644 --- a/lib/ansible/module_utils/shell.py +++ b/lib/ansible/module_utils/shell.py @@ -79,17 +79,15 @@ class Command(object): class Shell(object): - def __init__(self): + def __init__(self, prompts_re=None, errors_re=None, kickstart=True): self.ssh = None self.shell = None + self.kickstart = kickstart self._matched_prompt = None - self.prompts = list() - self.prompts.extend(CLI_PROMPTS_RE) - - self.errors = list() - self.errors.extend(CLI_ERRORS_RE) + self.prompts = prompts_re or CLI_PROMPTS_RE + self.errors = errors_re or CLI_ERRORS_RE def open(self, host, port=22, username=None, password=None, timeout=10, key_filename=None, pkey=None, look_for_keys=None, @@ -109,7 +107,10 @@ class Shell(object): self.shell = self.ssh.invoke_shell() self.shell.settimeout(10) - self.shell.sendall("\n") + + if self.kickstart: + self.shell.sendall("\n") + self.receive() def strip(self, data):