Ansible and FileBeta
and Ansible
2023-09-14 08:57:47 时间
使用Ansible通过ssh批量读取和修改Client设备
1. 安装ansible工具
apt-get install ansible
2. 添加需要访问的client信息
ansible配置文件如下
/etc/ansible/ansible.cfg
/etc/ansible/hosts
首先放开ansible.cfg中指定的hosts路径,然后编辑hosts如下:
[client] x.x.x.x ansible_ssh_user="user_name" ansible_ssh_pass="user_pwd" ansible_ssh_port=22
3. 安装sshpass
apt-get install sshpass
4. 执行命令
ansible client -m command -a "ls /root"
5. 用python在IP后添加ssh自动验证
#_*_coding:utf-8_*_ with open('client') as f_input: lines=f_input.readlines() with open('client_aaron', 'w') as f_output: for line in lines: f_output.write(line.replace(b'\n',b' ansible_ssh_user="usr_name" ansible_ssh_pass="usr_pwd" ansible_ssh_port=22\n')) f_input.close() f_output.close()
问题:
1. 首次登陆需要对ssh进行校验,会导致上述命令报错如下
ERROR: Using a SSH password instead of a key is not possible because Host key checking is enabled and sshpass does not support this. Please add this host's fingerprint to your known_hosts file to manage this host.
参见http://www.361way.com/ansible-cfg/4401.html 关闭ansible.cfg中的host_key_checking功能
相关文章
- ECOM6013 Topic 4 Website Design, Testing and Maintenance
- ORA-19728: data object number conflict between table string and partition string in table string ORACLE 报错 故障修复 远程处理
- ORA-00071: process number must be between 1 and string ORACLE 报错 故障修复 远程处理
- ORA-13620: The task or object string is read-only and cannot be deleted or modified. ORACLE 报错 故障修复 远程处理
- ORA-13640: The current operation was cancelled because it timed out, and was not in interruptible mode. ORACLE 报错 故障修复 远程处理
- ORA-13904: The file has been dropped and recreated during the procedure call. ORACLE 报错 故障修复 远程处理
- Scalaz(21)-类型例证:Liskov and Leibniz – type evidence详解编程语言
- MySQL:= and =“的意义(mysql和)
- MySQL中的OR与AND操作符比较(mysqlor和and)
- mysqlMySQL and MSSQL: Different Yet Compatible(mssqland)
- Oracle OJVM:学习和使用的最佳实践(Best Practices for Learning and Using Oracle OJVM)(oracleojvm)
- 深入浅出:MySQL中AND和OR运算符使用方法(mysql中and和or)
- The Power of Man and Linux: Redefining Computing(man.linux)
- Exploring the world of Linux GIFs: Tips and Tricks for Creating and Sharing Animated Images(linuxgif)
- Maximizing System Performance: A Guide to Using Linux SAR for Monitoring and Analysis.(linuxsar)
- Exploring the importance of TMPDIR and MySQL in Data Management(tmpdirmysql)
- StepbyStep Guide: Checking and Installing Oracle PSU Updates(oracle查看psu)
- Linux LSF: Improving Performance and Efficiency of LargeScale Computational Workloads.(linuxlsf)
- Maximizing Performance and Efficiency: Oracle Query Listener Best Practices(oracle查询监听)
- Oracle中使用除了And的其他查询关键字(oracle中除了and)
- and的区别Oracle数据库中的OR与AND的差异(oracle中or和)
- 2021 BMC Ecology and Evolution图像竞赛获奖作品赏析