场景一:
场景2:
我不明白为什么我必须先手动 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"
这是我添加的解决问题的行...
ansible_ssh_common_args = -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null