通过Ansible在EVE-NG实验室连接到新的设备节点

时间:2019-04-27 15:05:53

标签: ansible

我正在写一本ansible-playbook,它将对EVE-ng实验室中的新节点(cisco虚拟设备)进行初始配置。

让我解释一下与新EVE-NG实验节点的常规连接(以我为例) 我创建了一个实验室,添加了节点,然后看到了指向该节点的链接

telnet://192.168.1.183:32902

所以我能够打开任何telnet客户端,然后键入telnet 192.168.1.183 32902,然后按Enter并转到设备

 ➤ telnet 192.168.1.183 32902
Trying 192.168.1.183...
Connected to 192.168.1.183.
Escape character is '^]'.

我无法做的事情:按下Enter键,然后查看下一行:

% Please answer 'yes' or 'no'.
Would you like to enter the initial configuration dialog? [yes/no]:

键入“ no”,然后按Enter 然后我等待一段时间进行引导

Press RETURN to get started!

*Apr 27 13:15:34.997: %CTS-6-ENV_DATA_START_STATE: Environment Data Download in start state
*Apr 27 13:15:37.355: %LINEPROTO-5-UPDOWN: Line protocol on Interface VoIP-Null0, changed state to up
*Apr 27 13:15:37.356: %LINK-3-UPDOWN: Interface Ethernet0/0, changed state to up
*Apr 27 13:15:37.356: %LINK-3-UPDOWN: Interface Ethernet0/1, changed state to up
*Apr 27 13:15:37.356: %LINK-3-UPDOWN: Interface Ethernet0/2, changed state to up
*Apr 27 13:15:37.356: %LINK-3-UPDOWN: Interface Ethernet0/3, changed state to up
*Apr 27 13:15:38.356: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to up
*Apr 27 13:15:38.356: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/1, changed state to up
*Apr 27 13:15:38.356: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/2, changed state to up
*Apr 27 13:15:38.356: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/3, changed state to up
*Apr 27 14:04:53.696: %LINK-5-CHANGED: Interface Ethernet0/0, changed state to administratively down
*Apr 27 14:04:53.696: %LINK-5-CHANGED: Interface Ethernet0/1, changed state to administratively down
*Apr 27 14:04:53.706: %LINK-5-CHANGED: Interface Ethernet0/2, changed state to administratively down
*Apr 27 14:04:53.706: %LINK-5-CHANGED: Interface Ethernet0/3, changed state to administratively down
*Apr 27 14:04:53.965: %SYS-5-RESTART: System restarted --
Cisco IOS Software, Linux Software (I86BI_LINUX-ADVENTERPRISEK9-M), Version 15.5(2)T, DEVELOPMENT TEST SOFTWARE
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2015 by Cisco Systems, Inc.
Compiled Thu 26-Mar-15 07:36 by prod_rel_team
*Apr 27 14:04:53.977: %CRYPTO-6-ISAKMP_ON_OFF: ISAKMP is OFF
*Apr 27 14:04:53.977: %CRYPTO-6-GDOI_ON_OFF: GDOI is OFF
*Apr 27 14:04:54.696: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/0, changed state to down
*Apr 27 14:04:54.696: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/1, changed state to down
*Apr 27 14:04:54.711: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/2, changed state to down
*Apr 27 14:04:54.711: %LINEPROTO-5-UPDOWN: Line protocol on Interface Ethernet0/3, changed state to down
*Apr 27 14:04:55.519: %IP-5-WEBINST_KILL: **Terminating DNS process**

然后我再按Enter键一次,然后看到“ Router>”行。 在这里,我们启用,输入,确认等...

所以我正在写一本剧本...这是草稿:

---
 - name: to cisco CLI with telnet 
   connection: local
   gather_facts: false
   hosts: eveng
   tasks:

   - name: path to Router>
     telnet:
       port: 32902

user是用于login_prompt的Enter,而对于“您想进入初始配置对话框吗?”行则是“ no \ r \ n”。 [是/否]:'

user: "\r\nno\r\n"

下一行查找“转义字符为'^]'的部分。

然后我告诉telnet模块,这是login_prompt,并要求在该行之后粘贴用户

   login_prompt: "'."
   prompts:
     - ">"
   command:
     - "\r"

第一个任务已经完成,我认为这意味着我必须先获得“ Router>”行

在这里,我等待“否”后启动设备

   - name: sleep for 10 seconds and continue with play
     wait_for: timeout=10
     delegate_to: localhost

下一个任务(实际上与第一个任务相同)

  • 名称:路由器#的路径  telnet:    端口:32901

但是我在这里告诉Playbook,login_prompt和login是:

   user: "\ren\r"
   login_prompt: "Router>"

下一个:

       prompts:
         - "[#]"
       command:
         - terminal length 0
         - show clock
         - "\r"
     register: output
   - name: Debug output
     debug: var=output.outpu

看起来不错,但不工作或工作很奇怪。当我用ansible-playbook eveng.yml -v启动剧本时 它去了:

TASK [path to Router>]  *************************************task path:
/mnt/c/Users/leorikz/YandexDisk/0003_Learning/0005_Ansible/eveng.yml:8`

然后冻结,然后转到cmd进行telnet IP端口 然后按Enter 然后剧本继续前进

所以,这里的单词真的太多了

请帮助我使剧本正常工作或告诉我为什么我不能那样做

是的,我知道telnet-很烂,我必须使用SSH

但这是EVE-NG节点中的telnet

是的,我可以自己做几个节点,但是我的实验室不是几个节点,它们不仅仅适合我

tldr: 让我为EVE-ng实验室中的新节点(cisco虚拟设备)的初始配置创建一个ansible-playbook。

谢谢。

0 个答案:

没有答案