ansible - cisco IOS and “reload” command

前端 未结 5 512
梦如初夏
梦如初夏 2021-01-27 02:37

I would like to send command \"reload in \" to Cisco IOS, but that specific command needs to be confirmed like below:

#reload in 30
Reload scheduled in 30 minut         


        
相关标签:
5条回答
  • 2021-01-27 02:49

    Ansible 2.2 only

    You could use something like this:

      - name: send reload command inc confirmation
        ios_command:
          commands: 
            - reload in 30
            - y
          wait_for: 
            - result[0] contains "Proceed with reload" 
          provider: "{{ cli }}"
    

    Not tested but similar to last example for ios_command module.

    Take care with Ansible 2.2 though, it's not released yet and new releases of Ansible can have significant regressions.

    Ansible 2.0+ includes the expect module but that requires Python on the remote device, so it won't work on IOS or similar devices.

    0 讨论(0)
  • 2021-01-27 02:54

    You can use:

    - name: reload device
      ios_command:
        commands:
          - "reload in 1\ny"
        provider: "{{ cli }}"
    

    This will reload the device in 1 minute and the reload prompt gets accepted. It works well for ansible because the default prompt of ios will come back (reload gets triggered in 1 minute).

    Regards, Simon

    0 讨论(0)
  • 2021-01-27 03:02

    commands parameter of ios_command module expects a YAML formated list of commands. However in the code example provided commands parameter is set multiple times. Try the ios_command task like this:

    - name: do reload in case of "catting off"
      ios_command:
        commands:
          - reload in 30
          - y
      provider: "{{ cli }}"
    
    0 讨论(0)
  • 2021-01-27 03:02

    It appears that the simplest method would be to use the 'raw' module to send raw SSH commands to the device.

    This avoids having to use expect and having to play around with the ios_command module.

    The raw module will run the commands without caring what responses or prompts the device.

    0 讨论(0)
  • 2021-01-27 03:04

    Below worked for me with ansible-playbook 2.9.0 and Python 3.7. Please note that, on line with - command, make sure to use double quote " instead of single one '. And don't forget to put \n at the end of command.

        - name: Reloading switch using ios_command.
          ios_command:
            commands: 
              - command: "reload\n"
                prompt: 'Proceed with reload? [confirm]'
                answer: "\r"
    
    0 讨论(0)
提交回复
热议问题