1、copy模块
拷贝文件的模块。
参数:
src : 本地需要复制的文件的路径
dest : 复制到远程的某一个路径
owner :指定属主
group : 指定属组
mode : 设置权限的
backup : 是否备份
content : 指定文件内容
follow : 是否处理软连接
2、file模块
创建文件。
参数:
path : 需要创建的文件路径
owner :指定属主
group : 指定属组
mode : 设置权限的
state :状态
link : 软连接
src : 源文件地址
dest: 软连接地址
touch : 创建文件
directory : 创建目录
absent : 删除
recurse :递归授权
3、service
用来管理系统服务。
参数:
name : 指定需要操作服务的名称
state:
started #启动服务
stopped #停止服务
restarted #重启服务
reloaded #重载服务
enabled :开机自启动
4、systemd
用来管理系统服务。但是systemd底层需要systemd服务来支撑,没有systemd的操作系统无法使用。
5、group模块
用来管理用户组
参数:
name: somegroup #组名字
state:
present #创建组
absent #删除组
gid: 666 #指定组id
6、user模块
用来管理用户
参数:
name #用户名字
comment #用户备注
uid #用户id
group #用户所在的组名字
shell
/bin/bash #用户可以登录
/sbin/nologin #用户不需要登录
state
absent #删除用户
present #创建用户
remove #移除家目录
create_home #是否创建家目录
true #创建家目录
false #不创建家目录
7、cron模块
定时任务管理模块。
参数:
name #定时任务的备注
minute #分钟
hour #小时
day #日
month #月
weekday #周
job #指定的定时任务内容
state
present #新建定时任务
absent #删除定时任务
disabled
yes #注释定时任务
no #取消注释
8、mount
挂载文件系统。
参数:
path #本机准备挂载的目录
src #远端挂载点
fstype #指定挂载类型
opts #挂载参数(/etc/fstab中的内容)
state
present #配置开机挂载,将配置写入自动挂载文件,并没有直接挂载
unmounted #取消挂载,但是没有删除自动挂载配置
#常用配置
mounted #配置开机挂载,并且直接挂载上
absent #取消挂载,并且删除自动挂载配置
9、selinux
用来管理系统selinux
参数:
state: disabled
10、firewalld
操作firewalld防火墙模块。
参数:
service:指定服务
permanent:是否永久生效
state:
enabled :允许通过
port:指定端口的
rich_rule:附加规则
source:指定网段
interface:指定网卡
masquerade:是否开启IP伪装
11、archive
压缩模块
参数:
path: /path/to/foo #要打包的内容
dest: /path/to/foo.tgz #打好的包与存放位置
format:gz
12、unarchive解压模块
解压模块
参数:
src #包的路径
dest #解压后的目标路径
remote_src
yes #包在受控端服务器上
no #包在控制端服务器上
13、setup
获取控制端信息的模块
14、案例
1、上传代码
ansible web01 -m unarchive -a "src=/root/mario.tar.gz dest=/usr/share/nginx/html remote_src=no"
2、安装nginx
ansible web01 -m yum -a "name=nginx state=present"
3、启动Nginx
ansible web01 -m service -a "name=nginx state=started"
[root@localhost ~]# ll
total 148
-rwxr-xr-x. 1 root root 3956 Feb 21 15:21 init.sh
-rw-r--r-- 1 root root 146052 Feb 20 15:35 mario.zip
[root@localhost ~]# unzip mario.zip
[root@localhost ~]# cd html5-mario/
[root@localhost html5-mario]# tar -czvf mario.tar.gz ./
[root@localhost html5-mario]# mv mario.tar.gz ..
上传代码
[root@localhost ~]# ansible web01 -m unarchive -a "src=/root/mario.tar.gz dest=/usr/share/nginx/html remote_src=no"