Ansible免密码登陆

1|0配置Linux主机无密码访问

1|1生成秘钥

ssh-keygen -t rsa Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: 73:80:07:fa:9a:0d:e0:0e:d1:c2:44:d2:d2:61:67:21 root@ansible The key's randomart image is: +--[ RSA 2048]----+ |o=E.+.. | |=oo+ . o | |ooo . . o | | + . . . . | |. . . . S . | | o = o | | . o . | | | | | +-----------------+

1|2将管理机上生成的秘钥发送到被管理机

ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.10 ssh-copy-id -i /root/.ssh/id_rsa.pub root@172.16.1.10

1|3测试是否不需要密码直接执行任务

ansible test -a "date" 172.16.1.10 | SUCCESS | rc=0 >> Fri Apr 6 21:47:21 CST 2018 172.16.1.11 | SUCCESS | rc=0 >> Fri Apr 6 21:47:21 CST 2018

2|0执行Ansible任务时的排错

  通过Ansible执行任务时代上-v参数,打开调试模式(加的v个数越多调试的输出信息越多,最多4个v):

  -v的情况下:

ansible test -a "date" -v Using /etc/ansible/ansible.cfg as config file 172.16.1.11 | SUCCESS | rc=0 >> Fri Apr 6 21:49:43 CST 2018 172.16.1.10 | SUCCESS | rc=0 >> Fri Apr 6 21:49:43 CST 2018

  -vv的情况下:

ansible test -a "date" -vv ansible 2.4.2.0 config file = /etc/ansible/ansible.cfg configured module search path = [u'/root/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules'] ansible python module location = /usr/lib/python2.7/site-packages/ansible executable location = /usr/bin/ansible python version = 2.7.5 (default, Nov 20 2015, 02:00:19) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] Using /etc/ansible/ansible.cfg as config file META: ran handlers 172.16.1.11 | SUCCESS | rc=0 >> Fri Apr 6 21:49:47 CST 2018 172.16.1.10 | SUCCESS | rc=0 >> Fri Apr 6 21:49:47 CST 2018 META: ran handlers META: ran handlers

__EOF__

本文作者StaryJie
本文链接https://www.cnblogs.com/jie-fang/p/10293182.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   StaryJie  阅读(1401)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 单元测试从入门到精通
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)
· winform 绘制太阳,地球,月球 运作规律
点击右上角即可分享
微信分享提示