07-18-2024 01:25 AM - edited 07-18-2024 01:29 AM
Trying to use ios_config module, with 'src' parameter pointing to a set of dynamically generated lines of configuration. We put these all together and send it to a final module which uses ios_config to try and configure the device. For one such scenario on one platform, i'm getting following prompt which is causing the workflow to time out;
Static entry in use, do you want to delete child entries? [no]:
(adding a clear ip nat trans forced command before the remove command doesn't clear the prompt appearing)
From what i can see, there doesn't seem to be a way to handle prompts within the ios_config module, and the other suggestions ive come across, which are to use cli_command or ios_command modules don't seem to allow me to specify a 'src' file, instead require the commands to be defined within the task. Is there a workaround? 
Solved! Go to Solution.
10-03-2024 12:32 AM
Handling interactive prompts like "Static entry in use, do you want to delete child entries? [no]:" can be tricky with modules like ios_config since it doesn’t have a built-in way to respond to such prompts. For this scenario, I suggest a different approach using a combination of cli_command and ios_config modules.
Use the cli_command Module: Use the cli_command module to perform the specific command that triggers the prompt and pass the required input using the wait_for and prompt options. This allows us to simulate a manual response to the interactive prompt.
Leverage ignore_errors: You can use ignore_errors on this specific command task so that the overall playbook execution is not halted if the command fails or the prompt appears unexpectedly.
Continue with ios_config: After handling the prompt, continue using ios_config for the rest of your configuration commands.
Here’s an example of how this could be structured in a playbook:
---
- name: Handle Interactive Prompt and Apply Configuration
  hosts: switches
  gather_facts: no
  connection: network_cli
  tasks:
    - name: Remove static NAT entry with prompt handling
      cli_command:
        command: "no ip nat inside source static tcp 10.1.1.1 80 192.168.1.1 80"
        prompt: "Static entry in use, do you want to delete child entries?"
        answer: "yes"
        wait_for: 5
      register: nat_removal_result
      ignore_errors: yes
    - name: Validate NAT removal
      debug:
        msg: "{{ nat_removal_result }}"
    - name: Apply configuration from file using ios_config
      ios_config:
        src: "/path/to/generated/config"
      when: nat_removal_result is succeeded
cli_command:
register and ignore_errors:
ios_config after Prompt Handling:
 
					
				
		
07-18-2024 04:07 AM
@pcook10 so what you are seeing is kinda of expected, ios_config module in ansible is designed for bulk configuration changes but lacks built-in prompt handling sadly. Check out https://docs.ansible.com/ansible/latest/collections/ansible/netcommon/cli_command_module.html he module is your best bet for interacting with prompts as you can use a loop to feed it commands from your dynamically generated configuration file.
10-03-2024 12:32 AM
Handling interactive prompts like "Static entry in use, do you want to delete child entries? [no]:" can be tricky with modules like ios_config since it doesn’t have a built-in way to respond to such prompts. For this scenario, I suggest a different approach using a combination of cli_command and ios_config modules.
Use the cli_command Module: Use the cli_command module to perform the specific command that triggers the prompt and pass the required input using the wait_for and prompt options. This allows us to simulate a manual response to the interactive prompt.
Leverage ignore_errors: You can use ignore_errors on this specific command task so that the overall playbook execution is not halted if the command fails or the prompt appears unexpectedly.
Continue with ios_config: After handling the prompt, continue using ios_config for the rest of your configuration commands.
Here’s an example of how this could be structured in a playbook:
---
- name: Handle Interactive Prompt and Apply Configuration
  hosts: switches
  gather_facts: no
  connection: network_cli
  tasks:
    - name: Remove static NAT entry with prompt handling
      cli_command:
        command: "no ip nat inside source static tcp 10.1.1.1 80 192.168.1.1 80"
        prompt: "Static entry in use, do you want to delete child entries?"
        answer: "yes"
        wait_for: 5
      register: nat_removal_result
      ignore_errors: yes
    - name: Validate NAT removal
      debug:
        msg: "{{ nat_removal_result }}"
    - name: Apply configuration from file using ios_config
      ios_config:
        src: "/path/to/generated/config"
      when: nat_removal_result is succeeded
cli_command:
register and ignore_errors:
ios_config after Prompt Handling:
 
					
				
				
			
		
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide