title: pexpect module responses in Ansible based on condition
body: <p>I am creating an ansible script to install splunk Universal Forwarder. If management port 8089 is not free, splunk service start doesnot work. It asks for user input:</p>
  <pre class="lang-json prettyprint-override"><code>{
    &quot;stdout_lines&quot;: [
      &quot;&quot;, 
      &quot;This appears to be your first time running this version of Splunk.&quot;, 
      &quot;&quot;, 
      &quot;Splunk software must create an administrator account during startup. Otherwise, you cannot log in.&quot;, 
      &quot;Create credentials for the administrator account.&quot;,
      &quot;Characters do not appear on the screen when you type in credentials.&quot;, 
      &quot;&quot;, 
      &quot;Please enter an administrator username: admin&quot;, 
      &quot;Password must contain at least:&quot;, 
      &quot;   * 8 total printable ASCII character(s).&quot;, 
      &quot;Please enter a new password: &quot;, &quot;Please confirm new password: &quot;, 
      &quot;&quot;, 
      &quot;Splunk&gt; Needle. Haystack. Found.&quot;, 
      &quot;&quot;, 
      &quot;Checking prerequisites...&quot;, 
      &quot;\tChecking mgmt port [8089]: not available&quot;, 
      &quot;ERROR: mgmt port [8089] - port is already bound.  Splunk needs to use this port.&quot;, 
      &quot;Would you like to change ports? [y/n]: &quot;
    ]
  }
  </code></pre>
  <p>I am using the <code>pexpect</code> module this way for username and password :</p>
  <pre class="lang-yaml prettyprint-override"><code>- name: Start splunk forwarder service
    expect:
      command:  /opt/splunkforwarder/bin/splunk start  --accept-license --answer-yes
      responses:
         (.*)Please enter an administrator username(.*): &quot;{{ Username }}&quot;
         (.*)Please enter a new password(.*): &quot;{{ Password }}&quot;
         (.*)Please confirm new password(.*): &quot;{{ Password }}&quot;
  </code></pre>
  <p>I want to add under <code>pexpect</code> responses - <code>Would you like to change ports? [y/n] :</code>.
  This should be executed only when below prompts for user.</p>
  <pre><code>execution stops with &quot;ERROR: mgmt port [8089] - port is already bound.  Splunk needs to use this port.&quot; 
  </code></pre>
  <p>Please let me know how I can achieve this?</p>