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

问题描述 投票:0回答:1

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

我是一个很生气的新手,但管理了一个简单的班轮以在开关中获取和设置选项。备份到tftp命令暂时不起作用。

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

[[警告]:在从backup-cisco-tftp.yml的第11行第9列构造映射时,发现重复的dict键(提示)。仅使用最后定义的值。

在任务上说:致命的:[SW3]:失败! => {“ ansible_facts”:{“ discovered_interpreter_python”:“ / usr / bin / python”},“ changed”:false,“ msg”:“自变量命令属于类型,我们无法转换为列表:无法转换到列表“}

代码是:

      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"

我想必须有一种方法等待文本并添加两次响应?

提前感谢

Wouter

ansible command prompt
1个回答
0
投票

请尝试以下操作

    - 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"
© www.soinside.com 2019 - 2024. All rights reserved.