Ansible连接失败:未知类型
我对ansible很陌生。我正在尝试开发一个原型,以自动化cisco路由器/交换机,目前正在使用直接连接GNS3模拟cisco路由器的virtualbox纯主机适配器尝试使用cisco C3600。运行Ubuntu服务器16.04的Virtualbox安装了Ansible版本2.6.2.cp 我正在尝试运行一些基本的show命令,并使用playbook将其保存到ubuntu服务器,但我一直遇到未知类型的错误。我能够使用Ansible临时命令运行show命令Ansible连接失败:未知类型,ansible,ansible-2.x,Ansible,Ansible 2.x,我对ansible很陌生。我正在尝试开发一个原型,以自动化cisco路由器/交换机,目前正在使用直接连接GNS3模拟cisco路由器的virtualbox纯主机适配器尝试使用cisco C3600。运行Ubuntu服务器16.04的Virtualbox安装了Ansible版本2.6.2.cp 我正在尝试运行一些基本的show命令,并使用playbook将其保存到ubuntu服务器,但我一直遇到未知类型的错误。我能够使用Ansible临时命令运行show命令 ansible 192.168.56.
ansible 192.168.56.111 -m ios_command -a "commands='show version'" -c local -u <u_name> -k
库存:
# This is the default ansible 'hosts' file.
#
# It should live in /etc/ansible/hosts
#
# - Comments begin with the '#' character
# - Blank lines are ignored
# - Groups of hosts are delimited by [header] elements
# - You can enter hostnames or ip addresses
# - A hostname/ip can be a member of multiple groups
# Ex 1: Ungrouped hosts, specify before any group headers.
## green.example.com
## blue.example.com
## 192.168.100.1
## 192.168.100.10
192.168.56.111
错误消息:
ansible-playbook 2.6.2
config file = /etc/ansible/ansible.cfg
configured module search path =
[u'/home/<username>/.ansible/plugins/modules',
u'/usr/share/ansible/plugins/modules']
ansible python module location = /usr/lib/python2.7/dist-packages/ansible
executable location = /usr/bin/ansible-playbook
python version = 2.7.12 (default, Dec 4 2017, 14:50:18) [GCC 5.4.0
20160609]
Using /etc/ansible/ansible.cfg as config file
setting up inventory plugins
Parsed /etc/ansible/hosts inventory source with ini plugin
Loading callback plugin default of type stdout, v2.0 from
/usr/lib/python2.7/dist-packages/ansible/plugins/callback/default.pyc
PLAYBOOK: backup_cisco_router.yaml
*****************************************************************
1 plays in backup_cisco_router.yaml
PLAY [192.168.56.111]
********************************************************************
TASK [Gathering Facts]
*******************************************************************
task path: /etc/ansible/playbooks/backup_cisco_router.yaml:2
<192.168.56.111> ESTABLISH LOCAL CONNECTION FOR USER: root
<192.168.56.111> EXEC /bin/sh -c 'echo ~root && sleep 0'
<192.168.56.111> EXEC /bin/sh -c '( umask 77 && mkdir -p "` echo
/root/.ansible/tmp/ansible-tmp-1535722277.58-97501065121445 `" && echo
ansible-tmp-1535722277.58-97501065121445="` echo
/root/.ansible/tmp/ansible-tmp-1535722277.58-97501065121445 `" ) && sleep 0'
Using module file /usr/lib/python2.7/dist-
packages/ansible/modules/system/setup.py
<192.168.56.111> PUT /home/<username>/.ansible/tmp/ansible-local-
1860jy6GrC/tmp3KDn_s TO /root/.ansible/tmp/ansible-tmp-1535722277.58-
97501065121445/setup.py
<192.168.56.111> EXEC /bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-
1535722277.58-97501065121445/ /root/.ansible/tmp/ansible-tmp-1535722277.58-
97501065121445/setup.py && sleep 0'
<192.168.56.111> EXEC /bin/sh -c '/usr/bin/python
/root/.ansible/tmp/ansible-tmp-1535722277.58-97501065121445/setup.py &&
sleep 0'
<192.168.56.111> EXEC /bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-
1535722277.58-97501065121445/ > /dev/null 2>&1 && sleep 0'
ok: [192.168.56.111]
META: ran handlers
TASK [run mutiple commands on remote nodes]
********************************************************
task path: /etc/ansible/playbooks/backup_cisco_router.yaml:8
<192.168.56.111> using connection plugin network_cli (was local)
<192.168.56.111> starting connection from persistent connection plugin
<192.168.56.111> local domain socket does not exist, starting it
<192.168.56.111> control socket path is
/home/<username>/.ansible/pc/bbb52332a5
<192.168.56.111>
The full traceback is:
Traceback (most recent call last):
File "/usr/bin/ansible-connection", line 87, in start
self.connection._connect()
File "/usr/lib/python2.7/dist-
packages/ansible/plugins/connection/network_cli.py", line 298, in _connect
ssh = self.paramiko_conn._connect()
File "/usr/lib/python2.7/dist-
packages/ansible/plugins/connection/paramiko_ssh.py", line 249, in _connect
self.ssh = SSH_CONNECTION_CACHE[cache_key] = self._connect_uncached()
File "/usr/lib/python2.7/dist-
packages/ansible/plugins/connection/paramiko_ssh.py", line 365, in
_connect_uncached
raise AnsibleConnectionFailure(msg)
AnsibleConnectionFailure: Unknown type
fatal: [192.168.56.111]: FAILED! => {
"msg": "Unknown type"
}
to retry, use: --limit @/etc/ansible/playbooks/backup_cisco_router.retry
PLAY RECAP
***********************************************************
192.168.56.111 : ok=1 changed=0 unreachable=0 failed=1
您应该从playbook中删除主机名、用户名和密码,并将其放入清单文件中
[all:vars]
ansible_connection=local
ansible_python_interpreter=/usr/bin/python
#ansible_ssh_common_args='-o UserKnownHostsFile=/dev/null'
ansible_ssh_common_args='-o UserKnownHostsFile=~/.ssh/known_hosts'
ansible_ssh_common_args='-o StrictHostKeyChecking=no'
ansible_ssh_user=ciscoadmin
ansible_ssh_pass=CiScO123
device_type=cisco_ios
[learn]
192.168.56.111
接下来,更正剧本中的主机语句
改变
hosts: 192.168.56.11
到
其他一切看起来都很好。如果仍然出现错误,请确保可以通过SSH从主机连接到路由器。还可以使用-vvvv运行ansible playbook以获取详细信息。我不熟悉网络模块和模块连接,但我不确定您是否使用了正确的连接方法,您应该使用network\u cli
hosts: 192.168.56.11
hosts: learning