5

I'm running a :

- command: vsx update-software ...

command to perform an update on a host, the command requests to enter "y" to go ahead with its exection.
Will the command be executed with "yes" by default or should I add an Ansdible directive to respond with "yes" ? if so which directive please ?

Doc
  • 133
  • 1
  • 1
  • 10

1 Answers1

6

Use the expect module,

- name: Upgrading Software
  expect:
    command: vsx update-software
    responses:
      'First Question in the prompt' : 'y'
      'Second Question in the prompt' : 'y'

More on expect can be found here.

franklinsijo
  • 17,784
  • 4
  • 45
  • 63
  • Answering "Y" sends another prompt that I should respond also with "Y" to. Should I add the other prompt like : `'Question 2 in the prompt' : 'y'` ? – Doc Mar 20 '20 at 08:24
  • 1
    You can add as many responses as it is required to it. Updated the answer – franklinsijo Mar 20 '20 at 08:26
  • Should the space before ':' be removed or is it okay ? – Doc Mar 20 '20 at 09:53
  • 1
    It is a dictionary, space surrounding the `:` should not cause errors. Try skipping the space and see if it works. Unable to test and confirm at the moment. – franklinsijo Mar 20 '20 at 09:55