0

when executes command on remote host we have to give inputs like below . when we give any thing wrong it has to ask second time.

This the response on Remote host when executed command:

*********************************************************
Install Private cloud edition(y/n): y
Enable Monitoring (y/n): y
Configure Firewall (y/n): y
*********************************************************
Enter Virtual IP/Hostname: ***.**.**.*
The Virtual Hostname/IP provided seems to be active
Enter Virtual IP/Hostname:

so I'm trying this from controller node .when I try for expect module where responses is used to match with the string on remote host .so i gave input using prompt but when i give wrong ip it is not stating any error at that point of time. can we achieve like which are there in responses it will get displayed on controller screen so user can give input from there then if we give wrong it will ask for second time.can someone help me on this

This is my code

     - pause:
        prompt: "Enter Virtual IP/Hostname: "
      register: VIP 
    - name: command

     expect:
        echo: yes
        command: "{{ va }} -c {{ cluster_name }}"
        responses:
          Install Private cloud edition\(y\/n\): "{{ Private.user_input }}"
          Enable Monitoring \(y\/n\): "{{ monitoring.user_input }}"
          Configure Firewall \(y\/n\): "{{ firewall.user_input }}"
          Enter Virtual IP/Hostname: "{{ VIP.user_input }}"

        timeout: 120
        echo: yes
      ignore_errors: yes
      register: promptt ```
Hari
  • 15
  • 8
  • Hi Hari, welcome to SO. Using `expect` really isn't a great fit for interactive use -- it's possible with plain expect, but highly, highly unlikely to be possible trying to do that in ansible. The best approach would be to use information available to ansible to try and pre-flight the inputs, before feeding them to the `{{ va }}` program -- is that possible in your setup? – mdaniel Feb 17 '21 at 21:30
  • @mdaniel Here ``{{ va }} `` is the part of command after it execution only we are getting responses then how can i modify it – Hari Feb 18 '21 at 09:45
  • Make a wrapper in shell for your's expect who use env var on your's remote server, install them with ansible and set env var with ansible too but isn't a good choice to use ansible with expect... – Derioss Feb 18 '21 at 13:15

0 Answers0