ansible常用模块入门

常用模块有以下几个

command

copy

shell

crond

yum

service

setup

1。command模块

ansible george -m command -a "ls"    (按照我目前的理解,command只能执行一条命令)格式为ansible 组名 -m 模块 -a 动作

2.copy模块

ansible george -m copy -a "src=/root/159/a.txt dest=/root/b mode=600"   注意复制的需要是文件才行,不能是文件夹,-a 后面跟的选项可以从下面的的结果选取

3.shell模块

ansible george -m shell -a "cat /root/b"   其中-a后面的动作还可以同时执行多条命令,只需用分号隔开即可

4.crond模块

ansible george -m cron -a 'name="test" minute=* day=* month=* weekday=* job="echo 1>>/root/d"'

5.yum模块

顾名思义,该模块可以管理软件的安装和卸载,state=present(安装) adsent(卸载)

ansible test -m yum -a 'name=tree state=present'

然而,我试着用shell模块进行安装软件,也是可以正常安装的。。

6.service模块

state = started | stopped | restarted

ansible test -m service -a 'name=httpd state=restarted'

7.setup模块

ansible george -m setup

#显示远程主机的所有信息(后面加-v显示详细信息)

原文地址:https://www.cnblogs.com/biaopei/p/10277914.html