Search code examples
ansiblecommandprompt

ansible: found a duplicate dict key (prompt)


I am trying to backup a cisco switch config to tftp with ansible.

I am an ansible newbie but managed simple one liners to get and set options in a switch. The backup to tftp command will not work for now.

apparently the command parameters are stored in a python dictionary and when i try to use prompt: and answer: options twice in one command i get an error.

[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.

at the task it says:

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"}

The code is:

      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"

I guess there must be a way to wait for text and add a response twice?

Thanks in advance

Wouter


Solution

  • Please try as below

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