ansible:找到重复的字典键(提示)

ansible: found a duplicate dict key (prompt)

我正在尝试使用 ansible 将 cisco 交换机配置备份到 tftp。

我是一个 ansible 新手,但管理简单的一个衬里来获取和设置开关中的选项。备份到 tftp 命令暂时不起作用。

显然,命令参数存储在 python 字典中,当我尝试在一个命令中使用提示:和回答:选项两次时,出现错误。

[WARNING]: While constructing a mapping from backup-cisco-tftp.yml, line 11, column 9, found a duplicate dict key (prompt). Using last defined value only.

在任务中它说:

fatal: [SW3]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/bin/python"}, "changed": false, "msg": "argument commands is of type <type 'dict'> and we were unable to convert to list: <type 'dict'> cannot be converted to a list"}

密码是:

      gather_facts: false
      connection: network_cli
      tasks:
      - name: backup to tftp
        ios_command:
          commands:
            command: "copy running-config tftp:"
            prompt: "remote host"
            answer: "1.5.1.2"
            prompt: "filename"
            answer: "backup-{{ inventory_hostname }}.txt"

我想一定有一种方法可以等待文本并添加两次响应?

提前致谢

沃特

请尝试如下

    - name: play
      hosts: effe
      gather_facts: false
      connection: network_cli
      tasks:
      - name: backup to tftp
        cli_command:
         command: "copy running-config tftp:"
         check_all: True
         prompt: 
          - "remote host"
          - "filename"
         answer: 
          - "1.5.1.2"
          - "backup-{{ inventory_hostname }}.txt"

唯一对我有用的方法是使用驻留在 [] 中的提示部分。我的错误是我指定了完整的提示,如“主机名或 IP 地址(control-c 中止):[2.2.2.2]?”我不得不选择“[2.2.2.2]”。

---
 - name: run commands that require answering a prompt
   hosts: ios_xr_routers:1.1.1.1
   gather_facts: no
   connection: network_cli
   vars:
     ansible_network_os: ios


   tasks:
   - name: backup
     cli_command:
      command: "copy running-config tftp://2.2.2.2/test vrf MGMT"
      check_all: True
      prompt:
       - "[2.2.2.2;MGMT]"
       - "[/test]"
      answer:
       - "2.2.2.2"
       - "test"