ios_command在尝试响应双重确认提示时中止

时间:2019-03-11 02:37:58

标签: ansible

我正在Cisco IOS路由器上设置根CA,并尝试使用ios_command模块运行命令crypto pki server my-ca start

在运行它时,会发生以下情况:

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)#

当尝试在ansible中自动执行此操作时,这就是我一直在尝试的方法:

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

运行剧本时的输出如下:

"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."
    ]
]

似乎第二个提示导致它只是通过提交“ \ r”来取消,而不是像在第一个提示中一样再次提交“ mypassword \ r”。

我给了ios_command提示符字符串'assword:',​​所以它应该与“ Password:”和“ Re-enter password:”都匹配,但这没什么区别。

有没有办法让ios_command模块处理这种双重提示?据我所知,我无法将密码放入crypto pki server my-ca启动命令中。

1 个答案:

答案 0 :(得分:0)

Ganesh Nalawade在Ansible project Google Group上的this thread上回答了这个问题。 他的回答如下:

您可以使用从Ansible 2.7版本开始提供的cli_command模块

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

可以对任务进行如下修改以支持多个提示。

- 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"
相关问题