4-24(模块详解)

模块详解

ansible-doc -l        查找模块

ansible-doc -s command 查找具体参数

1.1command/shell模块

执行一个命令在远程节点上(shell可以识别管道符)

相关参数

chdir=/tmp  相当于  cd /tmp

    "pwd creates=/etc" /etc不存在则pwd  || 假

"pwd removes=/etc" /etc存在则pwd    && 真

warn=False    忽略警告。

ansible oldboy  -m command -a "chmod 000 /etc/hosts warn=False"

1.2copy模块

拷贝模块

"src=/root"     本地文件

"dest=/root" 拷贝到目标文件

"owner=www" 指定文件属主

"group=www" 指定文件属组

"mode=0600" 指定文件权限 directory_mode递归设定

"force=yes" 强制覆盖文件,默认为yes

"content='aaa' dest=/a" 直接批量添加内容 

content | 多行

ansible oldboy -m copy -a "src=/etc/hosts dest=/tmp/test.txt owner=www group=www mode=0600"

1.3script模块(systemd)

在本地运行模块,等同在远程执行,不需要将脚本推送到目标主机

chmod +x yum.sh(有时需要加执行权限)

ansible oldboy -m script -a "/server/scripts/yum.sh"

1.4cron模块

定时任务

"minute"分 "hour"时 "day"日 "month"月 "weekday"周

"job='/bin/sh /server/scripts/a.sh'"

name="aa" 指定计划名字

state=absent 删除定时任务

=present 添加定时任务

disabled=yes 注释

1.5mount模块

挂载模块

"present" 开机挂载 仅将配置写入/etc/fstab

"mounted" 挂载设备 并将

"unmounted" 卸载设备 不清理(临时)

"absent" 卸载设备 清理/etc/fstab

ansible oldboy -m mount -a "src=172.16.1.31:/data path=/data fstype=nfs opts=defaults state=present"

src上东西挂载到path fstype文件格式  opts挂载设置  state 状态

1.6yum模块

安装卸载软件

"name=rsync" 软件名字

"state=installed" 状态

installed ,present 安装

remover,sbsent 移除

latest 安装最新

ansible old -m yum -a 'name=httpd state=installed'

1.7service模块(C7不用)

启动服务模块

1.8user模块

用户管理

1.9file模块

创建目录,创建文件

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容