Can ios_config handle responding to two prompts in a row?

Cross posted from stackoverflow

I’m setting up a root CA on a Cisco IOS router and trying to use the ios_command module to run the command crypto pki server my-ca start.

On running it, the following happens:

GW1(config)#do crypto pki server my-ca start
%Some server settings cannot be changed after CA certificate generation.
% Please enter a passphrase to protect the private key
% or type Return to exit
Password: 

Re-enter password: 

% Certificate Server enabled.
GW1(config)#

When trying to automate this in ansible, this is what I’ve been trying:

- name: Respond to double-password prompt
  ios_command:
    commands:
      - command: crypto pki server my-ca start
        prompt: 'assword:'
        answer: "mypassword\r"

The output when running the playbook is as follows:

"stdout_lines": [
    [
        "%Some server settings cannot be changed after CA certificate generation.", 
        "% Please enter a passphrase to protect the private key", 
        "% or type Return to exit", 
        "Password: ", 
        "", 
        "Re-enter password: ", 
        "% Aborted."
    ]
]

It looks like the second prompt causes it to just cancel out by submitting “\r” rather than submitting “mypassword\r” again like it does at the first prompt.

I gave the ios_command prompt string ‘assword:’ so it should have matched both "Password: " and "Re-enter password: " but that didn’t make a difference.

Is there a way to make the ios_command module handle this double-prompt? As far as I can tell, I can’t put the password into the crypto pki server my-ca start command.

Just noticed, my title here is wrong, it should be ‘ios_command’ not ‘ios_config’

You can use cli_command module available in Ansible 2.7 version onwards

https://docs.ansible.com/ansible/latest/modules/cli_command_module.html

The task can be modified as below to support multiple prompts.

- name: Respond to double-password prompt
  cli_command:
    commands:
      - command: crypto pki server my-ca start
        check_all: True
        prompt: 
         - "password"
         - "enter password"

        answer: 
          - "mypassword\r"
          - "mypassword\r"

Great, thanks for that.