2、fetch模块(从node1拉取文件到ansible主机端) 示例:[root@DB2 ansible]# ansible all -m fetch -a "src=/tmp/an.txt dest=/tmp" 3、command模块(在远程主机上执行命令,属于裸执行,非键值对显示;不进行shell解析。不支持管道功能) 示例:[root@DB2 ansible]# ansible all -m command -a "ifconfig" 4、shell模块(由于commnad只能执行裸命令(即系统环境中有支持的命令),至于管道之类的功能不支持,shell模块可以做到。) 示例:[root@DB2 ansible]# ansible all -m shell -a "ifconfig|grep eno" 5、file模块(设置文件属性(创建文件)) path=目标路径 group 目录属组 owner 属主
state=directory为目录,link为软件链接 示例:创建目录:[root@DB2 ansible]# ansible all -m file -a "path=/var/tmp/hello.dir state=directory" 创建软连接文件:[root@DB2 ansible]# ansible all -m file -a "src=/tmp/hi.txt path=/var/tmp/hi.link state=link" 6、cron模块(通过cron模块对目标主机生成计划任务) 分(minute)时(hour)日(day)月(month)周(week) name=(本次计划任务的名称) state=present生成(默认)|absent 删除(基于name) 示例1:对所有机器执行任务:每隔3分钟从time.windows.com同步时间(因为cron默认是生成任务,结尾不加state=present也表示生成任务) [root@DB2 ansible]# ansible all -m cron -a "minute=*/3 job='/usr/sbin/update time.windows.com &>/dev/null' name=update_time"
示例2:删除计划任务(结尾加state=absent为删除任务) [root@DB2 ansible]# ansible all -m cron -a "name=update_time state=absent"
7、yum模块(故名思义就是yum安装软件包的模块) enablerepo表示启用, disablerepo禁用某repo库
name 安装包名
state (present' orinstalled', latest')表示安装, (absent' or `removed') 表示删除 示例:通过安装epel扩展源并安装nginx [root@DB2 ansible]# ansible all -m yum -a"name=epel-release state=installed" [root@DB2 ansible]# ansible all -m yum -a"name=nginx state=installed"
8、service模块(服务管理模块) name:服务名
state:服务状态
enabled: 是否开机启动 true|false
runlevel: 启动级别 (systemed方式忽略) 示例:开机启动nginx:[root@DB2 ansible]# ansible all -m service -a "name=nginx state=started enabled=true"
9、script模块(把本地的脚本传到远端执行;前提是到远端可以执行,不要把Linux下的脚本同步到windows下执行;) 示例:直接在ansible上执行脚本 [root@DB2 01]# ansible all -m script -a "/root/01/scripts/test.sh"