1.ansible常用模块
ansible模块官方文档: 集合索引 — Ansible 社区文档
file 模块----用来创建文件或目录
path 路径
src 一般用于创建软连接
owner 属主
group 属组
mode 权限
state directory/touch/link/touch/systemd 模块----用来管理服务
name 服务名字
state 服务状态 started/restarted/stoppedcopy 模块-----用于发送配置文件
src 源文件
dest 目标地址
backup 文件存在是否备份
owner 属主
group 属组
mode 权限
lineinfile ----修改文件内容
path 文件地址
regexp 相当于正则,匹配行
line 往文件中追加内容
yum/apt/dnf 模块----用来安装软件
name 软件名称
state installed/removed(慎用)/lasted/present/absent(慎用)
cron ----用来修改或添加定时任务
name 定时任务名字
minute 分
hour 时
day 日
mounth 月
week 周
job 命令内容
state present/absent
mount ----挂载模块
src 源地址
dest 挂载点
state mounted 挂载并修改/etc/fstab absent卸载并修改/etc/fstab
fstype 挂载文件系统类型
2.利用ansible书写部署rsyncd服务的剧本
流程:
服务端
- 1. 下载rsyncd
- 2. 发送配置文件
- 3. 创建环境--创建共享目录, 压缩用户,创建密码文件,修改权限
客户端:
- 1. 准备密码文件即可
#rsync服务端部署
- hosts: bak
tasks:
- name: rsync服务端部署. 01.安装rsync服务
apt:
name: rsync
state: present
- name: 02.发送配置文件
copy:
src: ./rsyncd.conf
dest: /etc/
- name: 03.创建用户
user:
name: www
uid: 1999
state: present
- name: 04.创建共享目录
file:
path: /data
owner: www
group: www
state: directory
- name: 05.创建密码文件
file:
path: /etc/rsync.password
mode: 600
state: touch
- name: 06.追加密码
lineinfile:
path: /etc/rsync.password
line: lxb:1
- name: 07.启动服务
systemd:
name: rsync
state: started
#rsync客户端部署
- hosts: nfs
tasks:
- name: 01.创建密码文件
file:
path: /etc/rsync.client
mode: 0600
state: touch
- name: 02.追加密码
shell:
echo "1" > /etc/rsync.client
文章评论