首页 > 其他 > 详细

Ansible常用模块整理

时间:2018-12-18 23:14:14      阅读:136      评论:0      收藏:0      [点我收藏+]
一、添加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"

Ansible常用模块整理

原文:http://blog.51cto.com/13689359/2332346

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!