基本的telnet脚本即可复制到闪存驱动器

时间:2019-02-12 15:22:21

标签: ansible backup telnet cisco

我正在尝试使用ansible远程登录到Cisco交换机并应用copy startup-config disk0命令。

Ansible似乎永远无法通过   (?i)“目标文件名”:通过“期望”命令“请工作”

    ---
    - hosts: all
      gather_facts: false
      connection: local
      tasks:
      - name: telnet,login and execute command
        ignore_errors: true
        expect:
        command: telnet "{{ inventory_hostname }}"
        responses:
          (?i)password: "{{ password}}"
          (?i)#: copy startup-config disk0
          (?i)"Destination filename": "{{ lookup('pipe','date') }"
        echo: yes
      register: telnet_output

我得到的输出

ansible-playbook 2.7.6

配置文件= /etc/ansible/ansible.cfg   配置的模块搜索路径= [u'/ root / .ansible / plugins / modules',u'/ usr / share / ansible / plugins / modules']   ansible python模块位置= /usr/lib/python2.7/site-packages/ansible   可执行位置= / usr / bin / ansible-playbook   python版本= 2.7.5(默认,2018年10月30日,23:45:53)[GCC 4.8.5 20150623(Red Hat 4.8.5-36)] 使用/etc/ansible/ansible.cfg作为配置文件 / var / lib / awx / projects / 6500 / hosts不符合host_list要求,如果这是意外情况,请查看插件文档 / var / lib / awx / projects / 6500 / hosts不满足脚本要求,如果这是意外情况,请查看插件文档

PLAYBOOK:copy-startup.yml ******************************************** ****************************************************** ****************************************************** ****************************************************** *************** 在copy-startup.yml中播放1张

播放[全部] ******************************************* ****************************************************** ****************************************************** ****************************************************** **************************** META:运行处理程序

任务[远程登录,登录和执行命令] ****************************************** ****************************************************** ****************************************************** ****************************************************** **** 任务路径:/var/lib/awx/projects/6500/copy-startup.yml:6 致命的:[66.90.19.18]:失败! => {“ changed”:true,“ cmd”:“ telnet \” 66.90.19.18 \“”,“ delta”:“ 0:00:30.370396”,“ end”:“ 2019-02-12 10:09: 41.473716”,“ msg”:“命令超出超时”,“ rc”:null,“开始”:“ 2019-02-12 10:09:11.103320”,“ stdout”:“正在尝试66.90.19.18 ... \ r \ r \ n已连接至66.90.19.18。\ r \ r \ n转义字符为'^]'。\ r \ r \ n \ r \ n \ r \ n用户访问验证\ r \ n \ r \ n密码:\ r \ nLAB-6500-SUP2T#copy startup-config disk0 \ r \ nDestination filename [disk0]?“,” stdout_lines“:[”正在尝试66.90.19.18 ...“,”“,”已连接到66.90.19.18。“,” ”,“转义字符为'^]'。”,“”,“”,“”,“用户访问验证”,“”,“密码:”,“ LAB-6500-SUP2T#copy startup-config disk0”, “目标文件名[disk0]?”]} ...忽略

PLAY RECAP ********************************************* ****************************************************** ****************************************************** ****************************************************** ************************** 66.90.19.18:ok = 2更改= 1不可达= 0失败= 0

似乎永远不想写目标文件名[disk0]? 任何想法

2 个答案:

答案 0 :(得分:0)

(?i)"Destination filename"匹配带双引号的字符串。

您需要:

responses:
    '(?i)password': "{{ password}}"
    '(?i)#': copy startup-config disk0
    '(?i)Destination filename': "{{ lookup('pipe','date') }"

答案 1 :(得分:0)

   ---
   - hosts: '6500'
   gather_facts: true
   connection: local
   tasks:

   - name: telnet,login and execute command
     ignore_errors: true
     expect:
        command: telnet "{{ inventory_hostname }}"
        responses:
          (?i)Password: {{ password }}
         (?i)Destination filename [disk0]? : "{{ lookup('pipe','date +%Y-%m-%d-%H-%M') }} {{ inventory_hostname }}"
         (?i)#: copy startup-config disk0
         (?i){{COMMAND}}: exit
       echo: yes
      register: telnet_output

这似乎是我所需的最佳解决方案。我更改了操作顺序,但操作却步履蹒跚,

相关问题