Ansible系列教程-常用模块(二)

30次阅读
没有评论

一、模块介绍

#ansible-doc -l    # 列出 Ansible 支持的模块
#ansible-doc ping  # 查看该模块帮助信息

二、 远程命令模块(command / script / shell)

2.1 command

command 作为 Ansible 的默认模块,可以运行远程权限范围所有的 shell 命令,不支持管道符。
执行命令:ansible Client -m command -a "free -m" 返回内存信息

Ansible系列教程-常用模块(二)

2.2 script

script 的功能是在远程主机执行主控端存储的 shell 脚本文件,相当于 scp + shell 组合
远程执行本地脚本 #ansible Client -m script -a "/home/1.sh"我在脚本里写了date,命令。

Ansible系列教程-常用模块(二)

2.3 shell

shell模块基本和command相同,但是shell支持管道符
#ansible Client -m shell -a "/home/1.sh"

2.4 copy模块

# ansible Client -m copy -a "src=/home/1.sh dest=/tmp/ owner=root group=root mode=0755"

Ansible系列教程-常用模块(二)

进入到node1到tmp目录,查看文件是否存在。

Ansible系列教程-常用模块(二)

2.5 stat模块

获取远程文件状态信息,atime/ctime/mtime/md5/uid/gid 等信息
#ansible Client -m stat -a "path=/etc/selinux/config"

Ansible系列教程-常用模块(二)

2.6 yum软件包管理

#ansible Client -m yum -a "name=curl state=latest"

Ansible系列教程-常用模块(二)

2.7 远程主机 crontab 配置

#ansible Client -m cron -a "name='check dirs' hour='5,2' job='ls -alh > /dev/null'"

2.8 mount

#ansible Client -m mount -a "name=/mnt/data src=/dev/sd0 fstype=ext4 opts=ro state=present"

2.9 service

#ansible Client -m service -a "name=nginx state=stoped"
#ansible Client -m service -a "name=nginx state=restarted"
#ansible Client -m service -a "name=nginx state=reloaded"

2.10 user

#ansible Client -m user -a "name=allen comment='user allen'"
#shell > ansible Client -m user -a "name=allen state=absent remove=yes" 
正文完
 
oakcdrom
版权声明:本站原创文章,由 oakcdrom 2020-04-13发表,共计1142字。
转载说明:转载请注明出处。
评论(没有评论)