将远程处理发送到设备并使用 Ansible 进行简单的 ping 测试
Issue remoting into a device and doing a simple ping test with Ansible
按照在线和几本书中的说明进行操作后,我不确定为什么会发生这种情况。我感觉缺少设置,但这里是设置:
我正在尝试使用命令:
ansible all -u $USER -m ping -vvvv
显然使用 -vvvv 进行调试,但除了它表示正在尝试连接之外没有太多输出。我收到以下错误:
S4 | FAILED => FAILED: Authentication failed.
S4 代表交换机 4,这是我尝试在其上自动配置和显示命令的 Cisco 交换机。我 100% 知道我在 host_vars 文件中设置的密码是正确的,因为当我从标准 SSH 客户端使用它时它是有效的。
这是我在 ansible.cfg 文件中的非默认配置设置:
[defaults]
transport=paramiko
hostfile = ./myhosts
host_key_checking=False
timeout = 5
我的主机文件:
[cisco-switches]
S4
还有我的 host_vars S4 文件:
ansible_ssh_host: 192.168.1.12
ansible_ssh_pass: password
我当前的版本是 1.9.1,运行 在 Centos VM 上。我确实在交换机的管理接口上应用了 ACL,但它允许来自该特定 IP 的远程连接。
请指教。
由于您在 Cisco 交换机中使用 ansible 自动执行命令,我猜您想在不提示输入密码或要求按 [Y/N] 确认的情况下执行与交换机的 SSH 连接连接。
为此,我建议在交换机上配置 Cisco IOS SSH 服务器以执行基于 RSA 的用户身份验证。
首先,您需要在 Linux 盒子上生成 RSA 密钥对:
ssh-keygen -t rsa -b 1024
注意:您可以使用 2048 而不是 1024,但考虑到一些 IOS 版本将接受最多 254 个字符的 ssh public 密钥。
开关侧:
conf t
ip ssh pubkey-chain
username test
key-string
Copy the entire public key as appears in the cat id_rsa.pub
including the ssh-rsa and username@hostname.
Please note that some IOS versions will accept
maximum 254 characters.
You can paste multiple lines.
exit
exit
如果您需要 'test' 用户可以执行特权 IOS 命令:
username test privilege 15 secret _TEXT_CLEAR_PASSWORD_
然后,从 Linux 框测试连接,以便将开关添加到 known_hosts 文件。对于在 known_hosts 文件中找不到的每个 switch/host,这只会发生一次:
ssh test@10.0.0.1
The authenticity of host '10.0.0.1 (10.0.0.1)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:d6:4b:d1:67.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.1' (RSA) to the list of known hosts.
ciscoswitch#
ciscoswitch#exit
最后使用 ansible 通过 SSH 和原始模块测试连接,例如:
ansible inventory -m raw -a "show env all" -u test
希望你觉得有用。
按照在线和几本书中的说明进行操作后,我不确定为什么会发生这种情况。我感觉缺少设置,但这里是设置:
我正在尝试使用命令:
ansible all -u $USER -m ping -vvvv
显然使用 -vvvv 进行调试,但除了它表示正在尝试连接之外没有太多输出。我收到以下错误:
S4 | FAILED => FAILED: Authentication failed.
S4 代表交换机 4,这是我尝试在其上自动配置和显示命令的 Cisco 交换机。我 100% 知道我在 host_vars 文件中设置的密码是正确的,因为当我从标准 SSH 客户端使用它时它是有效的。
这是我在 ansible.cfg 文件中的非默认配置设置:
[defaults]
transport=paramiko
hostfile = ./myhosts
host_key_checking=False
timeout = 5
我的主机文件:
[cisco-switches]
S4
还有我的 host_vars S4 文件:
ansible_ssh_host: 192.168.1.12
ansible_ssh_pass: password
我当前的版本是 1.9.1,运行 在 Centos VM 上。我确实在交换机的管理接口上应用了 ACL,但它允许来自该特定 IP 的远程连接。
请指教。
由于您在 Cisco 交换机中使用 ansible 自动执行命令,我猜您想在不提示输入密码或要求按 [Y/N] 确认的情况下执行与交换机的 SSH 连接连接。
为此,我建议在交换机上配置 Cisco IOS SSH 服务器以执行基于 RSA 的用户身份验证。
首先,您需要在 Linux 盒子上生成 RSA 密钥对:
ssh-keygen -t rsa -b 1024
注意:您可以使用 2048 而不是 1024,但考虑到一些 IOS 版本将接受最多 254 个字符的 ssh public 密钥。
开关侧:
conf t
ip ssh pubkey-chain
username test
key-string
Copy the entire public key as appears in the cat id_rsa.pub
including the ssh-rsa and username@hostname.
Please note that some IOS versions will accept
maximum 254 characters.
You can paste multiple lines.
exit
exit
如果您需要 'test' 用户可以执行特权 IOS 命令:
username test privilege 15 secret _TEXT_CLEAR_PASSWORD_
然后,从 Linux 框测试连接,以便将开关添加到 known_hosts 文件。对于在 known_hosts 文件中找不到的每个 switch/host,这只会发生一次:
ssh test@10.0.0.1
The authenticity of host '10.0.0.1 (10.0.0.1)' can't be established.
RSA key fingerprint is xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:d6:4b:d1:67.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.1' (RSA) to the list of known hosts.
ciscoswitch#
ciscoswitch#exit
最后使用 ansible 通过 SSH 和原始模块测试连接,例如:
ansible inventory -m raw -a "show env all" -u test
希望你觉得有用。