Ansible 备份运行配置模块错误

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

下面的代码是我非常简单的剧本,我在其中尝试登录交换机,获取正在运行的配置并将其保存到文件中。

我不断遇到错误: 任务 [获取运行配置] ********************************************** ****************** 致命:[imp1]:失败! => {"changed": false, "msg": "连接类型 ssh 对此模块无效"}

我尝试过使用模块“ios_command”和“ios_config”。都不起作用。我已经确认我确实可以通过 CLI SSH 到交换机。

`名称:备份思科交换机 主机:开关 收集事实:假

变量: ansible_user:我的用户 ansible_password: 我的密码

任务: - name: 获取运行配置 ios_命令: 命令: - 显示运行配置 注册:config_output

- name: Save running config to file
  copy:
    content: "{{ config_output.stdout[0] }}"
    dest: "/home/genesisjoec/Switch_Backups{{ inventory_hostname }}-running-config.txt"

`

两个模块都产生相同的结果。

automation ansible network-programming
1个回答
0
投票

来自

ios_command
模块文档:

该模块需要连接

network_cli
。请参阅https://docs.ansible.com/ansible/latest/network/user_guide/platform_ios.html

因此,您可以在库存中设置连接类型,或在游戏关卡上使用

vars

- name: Backup Cisco Switch
  hosts: SWITCHES
  gather_facts: false
  vars:
    ansible_user: myuser
    ansible_password: mypassword
    ansible_connection: ansible.netcommon.network_cli
  tasks:
    - name: Get running config
      ios_command:
        commands:
          - show running-config
      register: config_output

    - name: Save running config to file
      copy:
        content: "{{ config_output.stdout[0] }}"
        dest: "/home/genesisjoec/Switch_Backups{{ inventory_hostname }}
© www.soinside.com 2019 - 2024. All rights reserved.