Ansible常用模块整理

一、添加ansible主机

# vim /etc/ansible/hosts

    [server1]

    添加以下内容:

192.168.61.130 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=redhat
192.168.61.131 ansible_ssh_port=22 ansible_ssh_user=root ansible_ssh_pass=redhat

二、查看ansible模块

# ansible-doc -l

三、ansible常用模块

1.远程命令模块

command

Ansible默认模块,执行远程主机上的shell命令

# ansible server1 -m command -a "df -h"
scripts

在远程主机上执行主控端上的脚本

# ansible server1 -m script -a "/wh_k/test.sh"
shell

在远程主机上执行远程主机的脚本

# ansible server1 -m command -a "ls -l /wh_k/test.sh"
# ansible server1 -m command -a "chmod 751 /wh_k/test.sh"
# ansible server -m shell -a "/wh_k/test.sh"

2.copy模块

向远程主机拷贝文件

# ansible server1 -m copy -a "src=/wh_k/jmxcmd.jar dest=/wh_k/"

3.stat模块

获取远程主机文件的状态ctime、mtime等

# ansible server1 -m stat -a 'path=/wh_k/test.sh'

4.yum模块

远程主机软件包管理操作,yum、apt等

# ansible server1 -m yum -a 'name=httpd state=latest'

5.service模块

远程主机系统服务管理

# ansible server1 -m service -a 'name=httpd state=start'

6.user模块

远程主机用户

# ansible server1 -m user -a "name=wangwang"

转载于:https://blog.51cto.com/13689359/2332346

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值