CentOS7 3 模块介绍 ansible

ansible模块较多,对应可以查看相关文档,此处列出一下日常工作中常用的模块

【copy】模块

ansible agent -m copy -a "src=/root/test.sh dest=/tmp"

【file】

调用-s 参数,需要客户端能够无密码使用sudo命令;

ansible agent -m file -a "dest=/tmp/test.sh mode=755 owner=root group=root" -s

【script】

ansible agent -m script -a "/tmp/test.sh"

shell】创建用户

ansible agent -m shell -a "/tmp/test.sh" 

【group】创建组

ansible agent -m group -a "name=test1 state=present" -s

【user】

ansible agent -m user -a "name=xuel home=/home/xuel state=present" -s

【yum】

可以提供的status:absent,present,installed,removed,latest
ansible agent -m yum -a "name=httpd state=latest" -s

【server】

可以提供的status:running,started,stopped,restarted,reloaded

扫描二维码关注公众号,回复: 8749950 查看本文章

【cron】

ansible agent -m cron -a 'name="my job" minute=*/1 hour=* day=* month=* weekday=* job="/usr/sbin/ntpdate time1.aliyun.com"'

【get_url】

ansible agent -m get_url -a "url=http://mirrors.sohu.com/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm dest=/tmp"

【synchronize】需要安装rsync

ansible agent -m synchronize -a "src=/root/test.file dest=/tmp"
模块默认使用的为推送push,如果想使用pull功能需添加mode=pull
ansible agent -m synchronize -a "mode=pull src=/tmp/test.file dest=/root/"

【ini_file】

ansible agent -m ini_file -a "dest=/tmp/test.ini section=Mongo option=Host value=127.0.0.1"

该模块Python需要安装ConfigParser

转载自:https://www.centos.bz/2018/01/自动化运维工具ansible使用教程/

猜你喜欢

转载自www.cnblogs.com/xibuhaohao/p/12221078.html