0

I would like to know how can I pass multiple show commands in ios_command module in ad-hoc mode.

Sample with just one command:

ansible all -m ios_command -a "commands='show version'"

Now here I would like to send another command, say show run or any other.

Any suggestions on this would be appreciated.

techraf
  • 64,883
  • 27
  • 193
  • 198
DilrajSK
  • 5
  • 7

2 Answers2

1

You need to pass a list and you can do it using JSON string:

ansible all -m ios_command -a "commands='[ \"show version\", \"show run\" ]'"

If you leave the spaces out, you can squeeze to 'commands=["show version","show run"]'

techraf
  • 64,883
  • 27
  • 193
  • 198
  • Thanks I will try that and let you know – DilrajSK Jul 01 '18 at 13:42
  • Tried it out...its not working... Getting error as Invalid input detected. Any chance that you can test it out once in your environment? I have tried all the possible combinations that I could think of, but no luck – DilrajSK Jul 02 '18 at 02:48
0

I use the following:

ansible ios-device -m ios_command -a commands="{{ lookup('file', 'commands.txt') }}" -u username -k

where commands.txt contains

show version

You can add more commands on each line of the 'commands.txt' file.

leopal
  • 4,711
  • 1
  • 25
  • 35