我对ansible很陌生。我正在尝试使用直接连接GNS3模拟的cisco路由器的virtualbox(仅主机适配器)来自动化cisco路由器/交换机(当前尝试使用Cisco C3600)的原型。运行装有Ansible版本2.6.2.cp的Ubuntu Server 16.04的Virtualbox
我正在尝试运行一些基本的show命令,并使用剧本将其保存到ubuntu服务器,但是我一直收到Unknown type错误。我可以使用Ansible ad hoc命令运行show命令。
ansible 192.168.56.111 -m ios_command -a "commands='show version'" -c local -u <u_name> -k
有人可以告诉我我的剧本怎么了吗?
---
- hosts: 192.168.56.111
gather_facts: true
connection: local
tasks:
- name: run mutiple commands on remote nodes
ios_command:
host: 192.168.56.111
username: *****
password: *****
commands:
- show version
- show interfaces
- name: show run
ios_command:
commands:
- show run
host: 192.168.56.111
username: ****
password: ****
register: config
- name: save output to /etc/ansible/playbooks
copy:
content: "{{ config.stdout[0] }}"
dest: "/etc/ansible/playbooks/show_run.txt"
库存:
# 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
答案 0 :(得分:1)
您应该从剧本中删除主机名,用户名和密码,并将其放入清单文件中。
[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
到
hosts: learning
其他一切看起来都不错。如果仍然出现错误,请确保可以从主机SSH到路由器。还要使用-vvvv来运行ansible-playbook,以获取详细信息。