cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1032
Views
0
Helpful
5
Replies

Ansible IOS_config prompts

EditWu
Level 1
Level 1

Hello, I'm trying to convert our current switch configuration to IBNS configuration for 802.1x with ansible but ran into an issue that i'm trying to figure out.  I can get ansible to write "authentication display new-style" and remove some of the default lines that it generates like the class-map type control ... but when I get ansible to remove the policy-map type control.... lines it prompts with a message basically asking if i'm sure and expects a yes.  From what i've been reading, the ios_config modules waits for hostname(config)# to show back up before sending the next command and because of this ansible times out waiting for that prompt.  I've tied to use the cli_config module as well but it says that it doesn't support a connection type of local.  I'm not 100% sure what that means but is there a way to get the ios_config module to look for a different prompt so that i can continue?  Or ignore prompts so that i can send a "yes"?  Thanks.

5 Replies 5

Marcel Zehnder
Spotlight
Spotlight

Hi, try the cli_command module which is part of the ansible.netcommon collection. This module has prompt and answer parameters, which should do the trick. In order to use it in config mode there is an example provided (you need to adjust this to your case):

- name: run config mode command and handle prompt/answer
  ansible.netcommon.cli_command:
    command: '{{ item }}'
    prompt:
      - Exit with uncommitted changes
    answer: y
  loop:
    - configure
    - set system syslog file test any any
    - exit

https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/cli_command_module.html#ansible-collections-ansible-netcommon-cli-command-module

Thanks for the response.  I've actually tried cli_command and cli_config already and thought it would work but I get a "connection type local is not valid for this module".  I tried to add ansible_connection: network_cli but it didn't make a difference.  not sure what to try next to get cli_command or cli_config to work.

Can you try

ansible_connection: ansible.netcommon.network_cli

I've tried that also and I get the following, "conflicting action statements: ansible_connection, ansible.netcommon.cli_command"

Would setting ansible_connection elseware override whatever is defined in this block or would this take precedence?  

I would just configure it in the inventory.