goodluck 发表于 2024-7-22 11:26:34

自动化运维工具ansible操作手册

2、定义Host?Inventory
#?vim?/etc/ansible/hosts

172.16.10.22?ansible_ssh_user=root?ansible_ssh_pass=guoting
172.16.10.33?ansible_ssh_user=root?ansible_ssh_pass=guoting


copy模块
使用copy模块,可以将本地文件一键复制到远程服务器;?
-a后跟上参数,参数中指定本地文件和远端路径;
ansible myservers -m copy -a "src=/opt/app/bin/transfer.tar dest=~/"
ansible通过ssh登录到远程服务器后,并不执行.bash_profile来设置用户自定义的环境变量;如果我们暗算需要管理的目标服务器的路径不同,就不能直接写绝对路径,也不能写变量替换的路径;

command模块
command模块为ansible默认模块,不指定-m参数时,使用的就是command模块;?
comand模块比较简单,常见的命令都可以使用,但其命令的执行不是通过shell执行的,所以,像这些 "<", ">", "|", and "&"操作都不可以,当然,也就不支持管道;?


richest41 发表于 2024-7-22 13:22:11

感谢楼主分享

uqmeuqmeuqme 发表于 2024-7-29 23:40:18

多谢分享 多谢分享 多谢分享

mawr1985 发表于 2024-8-1 11:32:01

{:6_267:}
页: [1]
查看完整版本: 自动化运维工具ansible操作手册