-3

I have below shell script which require user input:

 read -e -p "Enter any string:" varible
 echo  'Entered value is ::' $varible > abc.txt

I wanted to run this script which requires user input in multiple servers and achieved using below yml :

- name: Here we start
  hosts: all

  tasks:  # is a list
  - name: Execute the user interactive script
  expect:                                                                   
       command: /usr/bin/sh /home/ansible/test.sh
       responses:
            "Enter any string:": "Success Script Executed"

But same if am trying using below command its not promoting for user input:

 ansible all -a 'sh /home/ansible/test.sh'

1)Please share correct ansible command that asks for user input for my script above.

2)Also for my script above please share correct ansible command that takes default value behalf user.

techraf
  • 64,883
  • 27
  • 193
  • 198
sudhir tataraju
  • 1,159
  • 1
  • 14
  • 30

1 Answers1

2

You can run any single Ansible module using the ansible command:

  • provide module name as a value to --module-name=MODULE_NAME (-m)

  • provide module arguments as a value to --args=MODULE_ARGS (-a)

In the case of the above task:

ansible all -m expect -a "command='/usr/bin/sh /home/ansible/test.sh' responses='{\"Enter any string:\": \"Success Script Executed\"}'"
techraf
  • 64,883
  • 27
  • 193
  • 198
  • Thank you, Could you tell me how can I mention two "responses" in the answer you provided ? also please answer to my 1st question aswell just in case if you know i.e 1)ansible command that asks for user input for my script above – sudhir tataraju Sep 13 '18 at 08:10