user2011902
user2011902

Reputation: 27

Ansible prompt for cisco-ios

I'm running ansible playbook that passes some aaa commands and everything runs fine until I hit this command: aaa accounting identity default start-stop group ISE-RADIUS-SERVERS

That command triggers following prompt when I run it directly on the switch:

Net-Lab-02(config)#aaa accounting identity default start-stop group ISE-RADIUS-SERVERS
This operation will permanently convert all relevant authentication commands to their CPL control-policy equivalents. As this conversion is irreversible and will disable the conversion CLI 'authentication display [legacy|new-style]', you are strongly advised to back up your current configuration before proceeding. 
Do you wish to continue? [yes]:

This is the playbook task that I'm running and I've tried million different variations but nothing seems to work:

  tasks:
    - name: Run commands that require answering a prompt
      cisco.ios.ios_command:
        commands:
          - command: "aaa accounting identity default start-stop group ISE-RADIUS-SERVERS"
            prompt: 'Do you wish to continue? \[yes\]:'
            answer: "yes"

I get following error:

fatal: [Net-Lab-02]: FAILED! => {"changed": false, "msg": "aaa accounting identity default start-stop group ISE-RADIUS-SERVERS\r\naaa accounting identity default start-stop group ISE-RADIUS-SERVERS\r\n ^\r\n% Invalid input detected at '^' marker.\r\n\r\nNet-Lab-02#"}

Upvotes: 0

Views: 135

Answers (1)

ha36d
ha36d

Reputation: 1127

aaa accounting identity is a command in config terminal mode and cisco.ios.ios_command module does not support running commands in configuration mode. Therefore you should use ios_config to configure IOS devices.

But handling interactive prompts like "Do you wish to continue? [yes]:" can be tricky with modules like ios_config since it doesn’t have a builtin way to respond to such prompts. For this scenario, cli_command can be used.

- name: Run commands that require answering a prompt
  ansible.netcommon.cli_command:
    command: "{{ item }}"
    prompt:
      - Do you wish to continue
    answer: y
  loop:
    - configure
    - aaa accounting identity default start-stop group ISE-RADIUS-SERVERS
    - exit

Upvotes: 2

Related Questions