test.yml
---
- name: CloudEngine
hosts: route
connection: network_cli
gather_facts: no
vars:
cli:
hosts: "{{inventory_hostname}}"
port: "{{ansible_ssh_port}}"
username: "{{ansible_ssh_user}}"
password: "{{ansible_ssh_pass}}"
transport: cli
tasks:
- name: "save config"
ansible.netcommon.cli_command:
command: '{{item}}'
prompt:
- Y/N
answer: Y
loop:
- system-view
- snmp-agent trap enable
- return
- save
register: output
- debug: msg={{output}}
ansible.cfg
[defaults] inventory = ~/.ansible/hosts host_key_checking = False timeout = 5
hosts
[route] 192.168.0.1 ansible_ssh_user=xxx ansible_ssh_pass="xxx" [route:vars] ansible_connection = network_cli ansible_network_os = ce ansible_port = 22 ansible_ssh_user = xxx ansible_ssh_pass = xxx
这是一个使用Ansible配置网络设备的示例。通过`test.yml`文件,Ansible连接到名为`route`的主机(192.168.0.1),使用网络CLI连接,并执行一系列命令来配置CloudEngine设备,包括进入系统视图,启用SNMP代理陷阱,保存配置。配置中还包含了处理用户输入提示和确认操作的步骤。
1850

被折叠的 条评论
为什么被折叠?



