ansible 梁

一、连接两台机器或多台
ssy-keygen -t rsa 生成公钥和私钥
ssh-copy -id -i 公钥 root@192.169.17.154 生成的公钥,传给服务器
ssh root@192.1698.17.153 确认连接上另一个服务器
二、ansible常用模块
1.远程命令模块( command / script / shell )

command 作为 Ansible 的默认模块,可以运行远程权限范围所有的 shell 命令,不支持管道符。
shell > ansible Client -m command -a "free -m" # 查看 Client 分组主机内存使用情况

script 的功能是在远程主机执行主控端存储的 shell 脚本文件,相当于 scp + shell 组合。
shell > ansible Client -m script -a "/home/test.sh 12 34" # 远程执行本地脚本

shell 的功能是执行远程主机上的 shell 脚本文件,支持管道符。
shell > ansible Client -m shell -a "/home/test.sh"           # 执行远程脚本
  1. copy 模块(实现主控端向目标主机拷贝文件,类似于 scp 功能)

    shell > ansible Client -m copy -a "src=/home/test.sh desc=/tmp/ owner=root group=root mode=0755"   # 向 Client 组中主机拷贝 test.sh 到 /tmp 下,属主、组为 root ,权限为 0755
  2. stat 模块(获取远程文件状态信息,atime/ctime/mtime/md5/uid/gid 等信息)
    shell > ansible Client -m stat -a "path=/etc/syctl.conf"
  3. get_url 模块(实现在远程主机下载指定 URL 到本地,支持 sha256sum 文件校验)

例:

shell > ansible Client -m get_utl -a "url=http://www.baidu.com dest=/tmp/index.html mode=0440 force=yes"
5.yum 模块(软件包管理)
shell > ansible Client -m yum -a "name=curl state=latest"
6.cron 模块(远程主机 crontab 配置)
shell > ansible Client -m cron -a "name='check dirs' hour='5,2' job='ls -alh > /dev/null'"
7.mount 模块(远程主机分区挂载)
shell > ansible Client -m mount -a "name=/mnt/data src=/dev/sd0 fstype=ext4 opts=ro state=present"
8.service 模块(远程主机系统服务管理)
shell > ansible Client -m service -a "name=nginx state=stoped"
shell > ansible Client -m service -a "name=nginx state=restarted"
shell > ansible Client -m service -a "name=nginx state=reloaded"

  1. user 服务模块(远程主机用户管理)
    shell > ansible Client -m user -a "name=wang comment='user wang'"

    shell > ansible Client -m user -a "name=wang state=absent remove=yes" # 添加删除用户

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值