ANSIBLE

## ansible

“`sh
[root@m01 ~]# yum install -y python3-pip
[root@m01 ~]# pip3 install -i https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple ansible

[root@m01 ~]# echo ‘export PATH=/usr/local/bin/:$PATH’ >>/etc/profile
[root@m01 ~]# source /etc/profile
[root@m01 ~]# ansible –version

[root@m01 /etc/ansible]# cat ansible.cfg
[defaults]
interpreter_python=/usr/bin/python3
host_key_checking = False
deprecation_warnings = False
[inventory]
[privilege_escalation]
[paramiko_connection]
[ssh_connection]
[persistent_connection]
[accelerate]
[selinux]
[colors]
[diff]
[root@m01 /etc/ansible]# cat hosts
[web]
172.16.1.[7:8]

[backup]
172.16.1.41

[nfs]
172.16.1.31

[data:children]
backup
nfs

“`

![image-20250107123925048](D:\Program Files (x86)\Typora\ansible\image-20250107123925048.png)

在主机清单中指定用户密码,

“`sh
172.16.1.9 ansible_user=root ansible_password=XZnh@95599 absible_port=22
“`

![image-20250107123941746](D:\Program Files (x86)\Typora\ansible\image-20250107123941746.png)

71:host_key_checking = False 这个配置没有关闭.关闭主机认证.

### 5.1 命令与脚本类模块

#### 1 command模块

“`sh
[root@m01 ~]# ansible all -m command -a ‘ip a s ens33’

-m command是默认的,可以省略
[root@m01 ~]# ansible all -a ‘ip a s ens33’

“`

#### 2 shell模块

与command模块相似,但是shell支持特殊符号

“`sh
[root@m01 ~]# ansible all -m shell -a ‘find /etc/sysconfig/network-scripts/ -name *ens33’

[root@m01 ~]# ansible all -m shell -a ip a show ens33 | awk -F ‘[ /]+’ ‘NRR==3{print \$3}'”

“`

#### 3 script模块

“`sh
ansible all -m script -a ‘/server/scripts/ansible/scripts.sh’
“`

文件相关模块

#### 4 file模块

案例05-创建/opt/ysl.txt

“`sh
[root@m01 ~]# ansible all -m file -a ‘path=/opt/ysl.txt state=touch’
“`

案例06-创建目录/app/

“`sh
[root@m01 ~]# ansible all -m file -a ‘path=/app/a/ state=directory’
“`

案例07-创建软连接,/etc/hosts创建软连接到/opt下

“`sh
[root@m01 ~]# ansible all -m file -a ‘src=/etc/hosts path=/opt/hosts state=link’
“`

案例08-创建/ans-backup目录,所有者是rsync,权限是700

“`sh
[root@m01 ~]# ansible all -m file -a ‘path=/ans-backup owner=rsync group=rsync mode=700 state=directory’

mode参数最好写4位0700,rsync必须存在,不然会报错
“`

案例09-删除/ans-backup

“`sh
[root@m01 ~]# ansible all -m file -a ‘path=/ans-backup state=absent’
“`

#### 5 copy模块

ansible-doc -s

案例10-分发属性好的/etc/hosts文件,如果文件存在则备份下

“`sh
[root@m01 ~]# ansible all -m copy -a ‘src=/etc/hosts dest=/etc/hosts backup=yes’

可以分发文件、压缩包,不推荐目录
copy是推送

fetch是拉取
[root@m01 ~]# ansible all -m fetch -a ‘src=/etc/hostname dest=/root/’
拉取后会在/root/目录下出现以所有主机清单的IP命名的目录,目录里有etc目录,hostnamectl在etc目录下

“`

#### 6 服务管理-systemd

systemd模块适用于目前大部分的Linux系统.

service模块适用于管理旧的Linux系统

案例11-开启crond服务并设置开机启动

案例12-关闭firewalld服务不让开机启动

案例13-重启sshd服务

“`sh
[root@m01 ~/172.16.1.31/etc]# ansible all -m systemd -a ‘name=crond enabled=yes state=started’

[root@m01 ~/172.16.1.31/etc]# ansible all -m systemd -a ‘name=firewalld enabled=no state=stopped’

[root@m01 ~]# ansible all -m systemd -a ‘name=sshd state=restarted’

“`

#### 7 软件管理

yum模块

“`sh
[root@m01 ~]# ansible all -m yum -a ‘name=htop,tree,lrzsz,sshpass’

[root@m01 ~]# ansible all -m yum -a ‘name=htop state=absent’

[root@m01 ~]# ansible all -m yum -a ‘name=rsync state=present’ 安装,默认可以不写

[root@m01 ~]# ansible all -m yum -a ‘name=rsync state=latest’ 安装或更新

“`

#### 8 get_url模块

相当于wget命令

推荐在管理节点下载好,再使用copy模块分发

“`sh
[root@m01 ~]# ansible all -m get_url -a ‘url=”https://nginx.org/download/nginx-1.26.1.tar.gz” dest=/root/’

“`

#### 9 yum_repository模块

推荐写好后,再使用copy模块分发

“`sh
ansible backup \
-m yum_repository \
-a ‘name=epel
description=”Extra Packages for Enterprise Linux 7 –
$basearch”
baseurl=”http://mirrors.aliyun.com/epel/7/$basearch”
enabled=yes
gpgcheck=no
“`

#### 10 用户管理

user用户管理 : useradd,userdel,passwd,usermod修改用户信息

案例15-创建www-ans用户,uid2000的虚拟用户

“`sh
[root@m01 ~]# ansible all -m user -a ‘name=www uid=2000 shell=/sbin/nologin create_home=no state=present’

“`

案例16-批量更新密码

方法1

“`sh
[root@m01 ~]# ansible all -m user -a “name=ysl password={{‘ysl’ | password_hash(‘sha512’ , ‘ysl’)}} state=present”

将密码ysl生成哈希值,再加入ysl生成哈希,使别人不能破解
{{ ‘1’ | password_hash(‘sha512’, ‘ysl’) }}
表示1是密码,经过管道,传递给了password_hash()插件, sha512加密算法,ysl
是随机字符用于生成随机加密后的密码
“`

方法2

“`sh
[root@m01 ~]# ansible all -m shell -a ‘echo ysl007 | passwd –stdin ysl’

“`

#### 11 group模块

添加组

“`sh
[root@m01 ~]# ansible all -m group -a ‘name=ysltest gid=2005 state=present’
“`

删除组

“`sh
[root@m01 ~]# ansible all -m group -a ‘name=ysltest state=absent’
“`

#### 12 cron模块

作用:用于管理系统的定时任务.

替代了crontab -e或vi /var/spool/cron/xxx用户功能

![image-20250107124106193](D:\Program Files (x86)\Typora\ansible\image-20250107124106193.png)

创建定时任务

“`sh
[root@m01 ~]# ansible all -m cron -a ‘name=”test” job=”echo ysl >> /tmp/ysl.txt” state=present’

name是注释,如果是ansible添加的,可以通过注释来删除定时任务
“`

删除定时任务

“`sh
[root@m01 ~]# ansible all -m cron -a ‘name=”test” state=absent’

“`

#### 13 mount模块

案例17-挂载nfs01已有的共享目录到web01上的/mnt下

“`sh
[root@m01 ~]# ansible web -m mount -a ‘fstype=nfs src=172.16.1.31:/data/ path=/mnt state=mounted’

“`

| state参数可使用的值 | 含义 |
| ——————- | ———————– |
| absent | 卸载并修改fstab |
| unmounted | 卸载不修改/etc/fstab |
| present | 仅修改/etc/fstab 不挂载 |
| mounted | 挂载并修改/etc/fstab |
| remounted | 重新挂载 |

卸载

“`sh
ansible 172.16.1.7 -m mount -a ‘path=/mnt/ state=absent’
“`

### 5.2 剧本与变量

yaml格式的文件:空格,冒号

“`sh

– hosts: all
tasks:
– name: 01 打开冰箱门
shell: echo 01 >> /tmp/bingxiang.log

– name: 02 放进冰箱
shell: echo 02 >> /tmp/bingxiang.log

– name: 03 关上冰箱
shell: echo 03 >> /tmp/bingxiang.log

“`

### 5.3 案例02-创建目录并分发

步骤:
1.创建目录/server/files
2.管理机的/etc/hosts文件发送过去

“`sh
[root@m01 /server/scripts/playbook]# cat 02.dist_file.yml

– hosts: all
tasks:
– name: 01 创建目录
file:
path: /server/files/
state: directory
– name: 02 分发文件
copy:
src: /etc/hosts
dest: /server/files/

“`

### 5.4 案例03-批量添加定时任务

定时同步时间ntp.aliyun.com

“`sh
[root@m01 /server/scripts/playbook]# cat 03.cron_ntp.yml

– hosts: all
tasks:
– name: 批量同步时间
cron:
name: “sync time”
job: “/sbin/ntpdate ntp.aliyun.com > /dev/null 2>&1”
state: present
[root@m01 /server/scripts/playbook]#

“`

### 5.5 案例04-nfs服务

nfs服务端:在xxx上部署nfs服务,共享/backup-nfs目录,all_squash,匿名用户:www-ans uid 2999 2999

nfs客户端:web挂载 /ans-upload目录挂载nfs服务端共享的/backup-nfs(永久挂载)

服务端流程:

\1. 部署nfs-utils

\2. 修改配置文件 /etc/exports

/backup-nfs 172.16.1.0/24(rw,all_squash)

\3. 创建共享目录,改所有者

\4. 启动服务rpcbind,nfs

客户端:

\1. 安装nfs-utils

\2. 挂载与永久挂载

“`yaml
[root@m01 /server/scripts/playbook]# cat 04.nfs_mount.yaml

– hosts: nfs
tasks:
– name: 01.部署nfs-utils
yum:
name: rpcbind,nfs-utils
state: present
– name: 02.修改配置文件
lineinfile:
path: /etc/exports
line: /nfs/ans 172.16.1.0/24(rw,anonuid=2999,all_squash)

– name: 03.创建组
group:
name: www-ans
gid: 2999
state: present

– name: 04.创建用户
user:
name: www-ans
group: www-ans
uid: 2999
create_home: no
shell: /sbin/nologin
state: present

– name: 05.创建并修改数组
file:
path: /nfs/ans
owner: www-ans
group: www-ans
mode: 0755
state: directory

– name: 06.启动rpc服务
systemd:
name: rpcbind
state: started
enabled: yes
– name: 07.启动nfs服务
systemd:
name: nfs
state: reloaded
enabled: yes

– hosts: web
tasks:
– name: 01.安装服务
yum:
name: nfs-utils,rpcbind
state: present
– name: 02.创建组
group:
name: www-ans
gid: 2999
state: present
– name: 04.创建用户
user:
name: www-ans
group: www-ans
uid: 2999
create_home: no
shell: /sbin/nologin
state: present
– name: 05.创建并修改数组
file:
path: /app/web/ansv2-upload/
owner: www-ans
group: www-ans
mode: 0755
state: directory

– name: 05.挂载
mount:
fstype: nfs
src: 172.16.1.31:/nfs/ans
path: /app/web/ansv2-upload/
state: mounted

“`

### 5.6 剧本里创建文件添加多行

“`yaml
– name: Insert multiple lines into a file
blockinfile:
path: /path/to/your/file
block: |
This is the first line
This is the second line
This is the third line
create: yes
“`

### 5.7 ansible变量

#### 1 vars

ansible 变量命名规则:

\1. 与shell类似,不能以数字开头.

\2. 变量中仅包含_下划线即可.不要包含其他特殊符号.

案例05-批量创建/ysl/ysl/upload

“`yaml
[root@m01 /server/scripts/playbook]# cat 05.mk_dir.yaml

– hosts: all
vars:
dir: /ysl/ysl/upload
file: ysl.txt
tasks:
– name: mkdir directory
file:
path: “{{ dir }}”
state: directory
– name: touch file
file:
path: “{{ dir }}/{{ file }}”
state: touch

“`

如果变量是某个选项的开头,则变量引用的时候需要加上双引号

如果不是开头,则可以不用添加引号

多个变量在一起的时候只需要一个引号,多添加引号会报错

“{{ dir }}/{{ file }}”这个是对的,”{{ dir }}”/”{{ file }}”这个是错的

vars局限性:

vars只能在当前剧本中生效

使用两个花括号包起来,花括号中间有空格

在hosts和tasks中间使用

#### 2 变量文件vars_files

在hosts和tasks中间使用

例:

“`yaml
– hosts: web
vars_files:
– ./vars.yml
tasks:

vars.yaml格式
可以顶格写
cat vars.yaml
dir: /server/ans-test-01/
file: test02.txt
“`

#### 3 组变量

在剧本目录下创建一个all目录,再创建vars.yml

或者根据主机清单的分组建多个目录,然后再各个目录创建vars.yaml

“`yaml
[root@m01 /server/scripts/playbook]# tree group_vars/
group_vars/
├── all
│ └── vars.yml
├── backup
│ ├── nfs
│ └── vars.yml
└── web
└── vars.yml

“`

“`yaml
案例07-测试组变量
vim 07.group_vars_test.yml

– hosts: all
tasks:
– name: 01.创建目录
file:
path: “{{ dir }}”
state: directory
– name: 02.创建用户
user:
name: “{{ user }}”
shell: /sbin/nologin
create_home: no
state: present
– hosts: web
tasks:
– name: 01.创建目录
file:
path: “{{ web_upload }}”
state: directory
– hosts: nfs
tasks:
– name: 01.创建目录
file:
path: “{{ nfs_dir }}”
state: directory

创建vars文件
[root@m01 /server/scripts/playbook]# cat group_vars/all/vars.yml
#1.all
dir: /server/scripts/
user: www

#2.nfs
nfs_dir: /ans-data/web/

#3.backup
backup_dir: /ans-backup/nfsbackup/

#4.web
web_upload: /app/ans/web/upload/

“`

#### 4 facts变量

facts变量相当于是ansible内置变量,存放被管理机器的基本信息

运行剧本的时候会运行:**Gathering Facts** task任务

**Gathering Facts** :ansible收集被管理端基本信息.cpu,内存,磁盘,网络,系统

我们在剧本中使用facts变量,未来如果不用可以关闭gather facts功能,加速剧本运行效果

“`sh
查看某个主机facts变量
[root@m01 /server/scripts/playbook]# ansible 172.16.1.61 -m setup

“`

常用facts变量

“`sh
ansible_hostname #主机名
ansible_memtotal_mb #内存大小
ansible_processor_vcpus #cpu总数
ansible_default_ipv4.address #默认网卡ip
ansible_distribution #系统版本

debian
ansible_distribution_version #系统版本
ansible_date_time.date #年月日
“`

##### 1 案例08-输出常用基本信息到屏幕,系统基本信息写入到/etc/motd中

“`sh
vim 08.test_facts_vars.yml

– hosts: all
tasks:
– name: 01.调试变量
debug:
msg: |
“主机名:{{ ansible_hostname }}”
“内存:{{ ansible_memtotal_mb }}”
“cpu:{{ ansible_processor_vcpus }}”
– name: 02.保存到文件中
lineinfile:
path: /etc/motd
state: present
backup: true
create: true
line: |
主机名:{{ ansible_hostname }}
内存:{{ ansible_memtotal_mb }}
cpu核数:{{ ansible_processor_vcpus }}
系统:{{ ansible_distribution }}
系统版本:{{ ansible_distribution_version }}

[root@m01 /server/scripts/playbook]# ansible all -m shell -a “cat /etc/motd”

“`

debug模块用于在剧本中输出与调试,一般用于输出变量内容.

|表示下面的内容是多行,用于输出或写入多行到文件中,注意索引对齐

debug:

msg:

相当于 echo,msg后面也要加引号

##### 2 案例09-ans-facts变量和判断

麒麟系统安装cowsay
ubt系统安装cmatrix

“`yaml
– hosts: all
tasks:
– name: 麒麟系统安装cowsay
yum:
name: cowsay
state: present
when: ansible_distribution is match(“Kylin”)

– name: ubt系统安装cmatrix
apt:
name: cmatrix
state: present
when: ansible_distribution is match(“Ubuntu”)

– name: 输出
debug:
msg:”{{ ansible_distribution }}”
“`

\1. 通过facts变量获取系统的基本信息

\2. 通过facts变量获取信息并进行判断

\3. 如果不需要可以进行关闭,加速剧本的运行( gather_facts: false )

\4. 修改ansible.cfg #gathering = implicit去掉注释,永久关闭,后期剧本中需要开启gather_facts: true

“`sh
yes or no 还是True or false
在使用上是一致的,表示的是真(开启,启动),假(关闭).
布尔类型的数据:真,假.
真:yes,True,true
假:no,False,false
根据每个模块选项的说明去使用即可
“`

##### 3 关闭facts变量,加速剧本运行

默认开启,不使用的时候临时关闭: gather_facts: false hosts: tasks之间

彻底关闭,使用的时候在剧本中临时开启 gather_facts: true

“`sh
cat>/etc/ansible/ansible.cfg<、<、>=、<=、==、!= | 大于、小于、大于等于、小于等于、等于、不等于 | | is match("正则") | 例:ansible_hostname is match("web\|backup") | | is not match("正则") | 取反排除 | ```sh 关闭掉麒麟系统中每次提示的: 自动发现的pyhont问题. group_vars/all/vars.yml加入即可 ansible_python_interpreter: /usr/bin/python3 关闭麒麟或其他系统,对python3.7不支持的警告提示. sed -i 's@#deprecation_warnings = True@deprecation_warnings = False@g' /etc/ansible/ansible.cfg ``` ### 5.14 剧本调试 debug流程 目标通过注释,等等方法定位问题 #### 1 检查语法与单步执行 ```sh -C --check 模拟运行,不作出改变,一些变量可能会提示报错,因为-C没有真正运行 剧本. register变量无法使用(目前使用pip安装的是OK的). --syntax-check 只做语法检查,不运行. 高级:--step 单步运行. y执行这个task,n忽略这个task,c自动运行 [root@m01 /server/scripts/playbook]# ansible-playbook -i hosts --step 15.test_hadnlers.yml PLAY [nfs] ********************************************************************* Perform task: TASK: 1.分发文件 (N)o/(y)es/(c)ontinue: y ``` #### 2 从指定任务开始运行 ```sh 一般先用--list-tasks查看剧本中tasks名字 然后--start-at-task "任务名字" 从指定任务开始运行. ansible-playbook -i inventory --list-tasks 16.nfs_server_client_v2_handlers.yml ansible-playbook -i inventory --start-at-task "3.创建挂载点" 16.nfs_server_clit_v2_handlers.yml [root@m01 /server/scripts/playbook]# ansible-playbook -i hsots --list-tasks 13.rsync_server_client_v1.yml [WARNING]: Unable to parse /server/scripts/playbook/hsots as an inventory source [WARNING]: No inventory was parsed, only implicit localhost is available [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' [WARNING]: Could not match supplied host pattern, ignoring: backup playbook: 13.rsync_server_client_v1.yml play #1 (backup): backup TAGS: [] tasks: 1.部署rsync TAGS: [] 2.配置文件 TAGS: [] 3.用户组 TAGS: [] 4.目录,目录权限 TAGS: [] 5.服务端密码文件 TAGS: [] 6.启动服务端 TAGS: [] 7.查看端口 TAGS: [] 8.查看7的结果 TAGS: [] play #2 (all): all TAGS: [] tasks: 1.安装rsycn TAGS: [] 2.密码文件权限 TAGS: [] ``` #### 3 tag标签 ```sh 运行剧本的时候 --list-tasks 查看任务名字和标签名 -t --tags 运行的标签,如果多个标签通过","分割 --skip-tags 排除指定的tags,如果多个标签通过","分割 ``` ```sh [root@m01 /server/ans/playbooks]# cat 02.install_nfs.yml #nfs server服务端 - hosts: backup tasks: - name: 01. 安装nfs yum: name: nfs-utils,rpcbind state: present tags: - server_01_install - nfs_server - name: 02. 修改配置或分发 lineinfile: path: /etc/exports line: "/backup-nfs 172.16.1.0/24(rw,all_squash,anonuid=2999,anongid=2999)" #//backup-nfs 172.16.1.0/24(rw,all_squash,anonuid=2999,anongid=2999) tags: - server_02_conf - nfs_server - name: 03. 添加www-ans用户组 group: name: www-ans gid: 2999 state: present tags: - server_03_user - nfs_server - name: 03. 添加www-ans用户 user: name: www-ans shell: /sbin/nologin uid: 2999 ``` #### 4 忽略错误 运行剧本的时候,因为重复运行导致的错误提示,并不是真的错误. 比如:目录已经存在,用户已经存在. 在这种情况下,我们可以通过ignore_errors忽略错误,让剧本可以继续运行 ignore_errors: true ### 5.15 jinja2模版 #### 1 基本使用 ```sh [root@m01 /server/scripts/playbook]# cat 07.change_motd.yml - hosts: all gather_facts: no tasks: - name: 分发motd文件 template: src: templates/motd.j2 dest: /etc/motd backup: yes - name: 分发motd文件 copy: src: templates/motd.j2 dest: /tmp/motd backup: yes [root@m01 /server/scripts/playbook]# cat templates/motd.j2 ####################################### welcome to ysl elastic linux system 操作需谨慎,删根弹指间. 主机名: {{ ansible_hostname }} ip地址: {{ ansible_default_ipv4.address }} 内存大小: {{ ansible_memtotal_mb }} CPU数量: {{ ansible_processor_vcpus }} 核心总数: {{ ansible_processor_cores }} 发行版本: {{ ansible_distribution }} ``` #### 2 判断使用 ```sh [root@m01 /server/scripts/playbook]# cat 15.jinja2-if.yml - hosts: all tasks: - name: 分发配置文件 template: src: templates/keepalived.conf.j2 dest: /tmp/keepalived.conf [root@m01 /server/scripts/playbook]# tree templates/ templates/ ├── keepalived.conf.j2 └── motd.j2 0 directories, 2 files [root@m01 /server/scripts/playbook]# cat templates/keepalived.conf.j2 #this is keepalived.conf {% if ansible_hostname == "web01" %} state 主节点 {% elif ansible_hostname == "web02" %} state 备节点 {% endif %} 其他配置,都是相同的这里忽略 [root@m01 /server/scripts/playbook]# j2文件中判断 {% if ansible_hostname == "web02" %} state 备节点 {% elif ansible_hostname == "web01" %} state 主节点 {% endif %} ``` #### 3 循环 ```sh 配置文件 server.conf web服务器的/tmp/目录下 10.0.0.7 10.0.0.8 10.0.0.9 10.0.0.10 {% for ip in [1,2,3,4,5,6] %} 10.0.0.{{ ip }} {% endfor %} #range(2,11) 生成数字序列 2表示从2开始,到10结束 #顾头不顾腚 {% for ip in range(2,11) %} 10.0.0.{{ ip }} {%endfor%} {% for ip in ["ysl","oldwang"] %} 10.0.0.{{ ip }} {%endfor%} ``` ### 5.16 ansible进阶 #### 1 vault \#1.进行加密 ansible-vault encrypt 文件 #enable \#进行使用 ansible或ansible-playbook 加上--ask-vault-pass 即可 --ask-vault-pass 交互 --vault-password-file 密码文件 \#彻底解密 ansible-vault decrypt hosts# #### 2 roles Roles本质让我们书写剧本的时候有个目录规范. 把我们完整的剧本拆分若干部分,有的专门存放tasks部分(剧本),存放变量, 存放普通文件,存储变量文件,handlers内容 创建roles环境 ```sh [root@m01 /server/ans]# mkdir -p roles/{nfs-server,nfs-client}/{files,tasks,templates,handlers} [root@m01 /server/ans]# mkdir -p roles/group_vars/all [root@m01 /server/ans]# [root@m01 /server/ans]# tree -F roles/ roles/ ├── group_vars/ │ └── all/ ├── nfs-client/ │ ├── files/ │ ├── handlers/ │ ├── tasks/ │ └── templates/ └── nfs-server/ ├── files/ ├── handlers/ ├── tasks/ └── templates/ 12 directories, 0 files [root@m01 /server/ans]# 剧本安装nfs的yml文件 #nfs server服务端 - hosts: backup tasks: - name: 01. 安装nfs yum: name: nfs-utils,rpcbind state: present tags: - server_01_install - nfs_server - name: 02. 修改配置或分发 template: src: exports.j2 #文件里面可以放点变量 dest: /etc/exports backup: true notify: - restart_nfs tags: - server_02_conf - nfs_server - name: 03. 添加www-ans用户组 group: name: www-ans gid: 2999 state: present tags: - server_03_user - nfs_server - name: 03. 添加www-ans用户 剧本文件需要的文件内容 user: name: www-ans shell: /sbin/nologin uid: 2999 group: www-ans create_home: false state: present tags: - server_03_user - nfs_server - name: 04. 创建共享目录 file: path: /backup-nfs owner: www-ans group: www-ans state: directory tags: - server_04_dir - nfs_server - name: 05. 启动 rpc systemd: name: rpcbind enabled: true state: started tags: - server_05_start - nfs_server - name: 05. 启动 nfs systemd: name: nfs enabled: true state: started tags: - server_05_start - nfs_server handlers: - name: restart_nfs systemd: name: nfs state: restarted ```

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注