ansible之copy模块测试

模块简单介绍:
各模块位置(default=/usr/share/ansible)
各模块使用说明可以用“ansible-doc 【模块名称】”的方式查询,也可以使用-s蚕食来指定模块查询使用说明。
ansible-doc -s copy

例:把主控端/root 目录下的test.sh 文件拷贝到到指定节点上
测试文件test.sh

[root@master ~]# vim test.sh
#!/bin/sh
Time=`date +"%m-%d %H:%M"`
echo "$Time script testing success!"
  • 1.
  • 2.
  • 3.
  • 4.

ansible all -m copy -a “src=/root/test.sh dest=/tmp/”
[root@master ~]# ansible all -m copy -a “src=/root/test.sh dest=/tmp/”

paramiko: The authenticity of host '127.0.0.1' can't be established.
The ssh-rsa key fingerprint is 3d906ef1d450e4cc7031aef5e8c296f6.
Are you sure you want to continue connecting (yes/no)?
10.0.0.20 | SUCCESS => {
    "changed": true, 
    "checksum": "15bea568f36e8f8cbdce4f528232f34056673f2c", 
    "dest": "/tmp/test.sh", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "925ddc87eb89ecd133ddbb8028a762bf", 
    "mode": "0644", 
    "owner": "root", 
    "size": 76, 
    "src": "/root/.ansible/tmp/ansible-tmp-1469844893.62-139787019066912/source", 
    "state": "file", 
    "uid": 0
}
10.0.0.21 | SUCCESS => {
    "changed": true, 
    "checksum": "15bea568f36e8f8cbdce4f528232f34056673f2c", 
    "dest": "/tmp/test.sh", 
    "gid": 0, 
    "group": "root", 
    "md5sum": "925ddc87eb89ecd133ddbb8028a762bf", 
    "mode": "0644", 
    "owner": "root", 
    "size": 76, 
    "src": "/root/.ansible/tmp/ansible-tmp-1469844894.04-150966934090967/source", 
    "state": "file", 
    "uid": 0
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.

如果执行过程中出现错误;解决方法:
错误:

10.0.0.20 | FAILED! => {
"changed": false,
"checksum": "28adc51d1e42f06598325651d1fece8efd6eb907",
"failed": true,
"msg": "Aborting, target uses selinux but python bindings (libselinux-python) aren't
installed!"
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.

解决:关闭防火墙和selinux

posted @   勤奋的蓝猫  阅读(1)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· DeepSeek “源神”启动!「GitHub 热点速览」
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 我与微信审核的“相爱相杀”看个人小程序副业
· C# 集成 DeepSeek 模型实现 AI 私有化(本地部署与 API 调用教程)
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
点击右上角即可分享
微信分享提示