ssh 连接容器实验室失败

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

场景一:

  1. 使用 ansible ssh 到 csr1000v 路由器。
  2. Jenkins 返回 ssh 连接失败。

场景2:

  1. 部署容器csr1000v后,我手动ssh进入其中并保存指纹。
  2. 使用ansible ssh 进入csr1000v
  3. Jenkins 返回成功。

我不明白为什么我必须先手动 ssh 到 csr1000v 路由器才能允许 ansible 成功 ssh 到路由器进行配置。有什么解决方案可以解决这个问题吗?需要解决这个问题以实现自动化。

ansible.cfg

[defaults]
inventory = hosts
gathering = explicit
host_key_checking = False
retry_file_enabled = False

主持人

[cisco_routers]
#initial host adapter ip address
R1 ansible_host=172.20.20.2
[cisco_routers:vars]
ansible_user=admin
ansible_ssh_pass=admin

router_wsl.yaml

---
- name: see ip
  hosts: cisco_routers
  connection: network_cli

  vars:
    ansible_network_os: ios

  tasks:
    # Sets gigabit 2 ip address
    - name: Set ip for gigabit Ethernet 2
      ios_command:
        commands:
          - enable
          - configure terminal
          - interface gigabitEthernet 2
          - ip address 192.168.1.1 255.255.255.0
          - no shutdown
      ignore_errors: true

    # set ip for gigabit 3
    - name: set ip for gigabitEthernet 3
      ios_command:
        commands:
          - enable
          - configure terminal
          - interface gigabitEthernet 3
          - ip address 192.168.2.1 255.255.255.0
          - no shutdown
      ignore_errors: true

    # save configuration of router
    - name: Save configuration
      ios_command:
        commands: "write memory"

    # display interfaces
    - name: show ip
      ios_command:
        commands:
          - show ip interface brief
      register: interfaces

    - debug: msg="{{ interfaces }}"

    - name: Display running configuration
      ios_command:
        commands:
          - show running-config
      register: config

    # saves backup of the running config
    - name: Save output to ./backups/
      copy:
        content: "{{ config.stdout[0] }}"
        dest: "/var/jenkins_home/show_run_{{ ansible_host }}.txt"
ssh ansible containers
1个回答
0
投票

这是我添加的解决问题的行...

ansible_ssh_common_args = -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.