对每个人而言,真正的职责只有一个:找到自我。然后在心中坚守其一生,全心全意,永不停息。所有其它的路都是不完整的,是人的逃避方式,是对大众理想的懦弱回归,是随波逐流,是对内心的恐惧 ——赫尔曼·黑塞《德米安》
涉及到的文件
[student@workstation filestorage-automation]$ ls
ansible.cfg inventory nfs_client.yml nfs_server.yml smb_client.yml smb_server.yml smb_vars.yml templates
[student@workstation filestorage-automation]$ tree .
.
├── ansible.cfg
├── inventory
├── nfs_client.yml
├── nfs_server.yml
└── templates
└── share.exports.j2
配置文件和主机清单文件,不多解释
[student@workstation filestorage-automation]$ cat ansible.cfg
[defaults]
inventory=inventory
remote_user=devops
[student@workstation filestorage-automation]$ cat inventory
[servers]
serverd.lab.example.com
[clients]
servera.lab.example.com
serverb.lab.example.com
serverc.lab.example.com
[student@workstation filestorage-automation]$
[student@workstation filestorage-automation]$ cat nfs_client.yml
---
- name: Access an NFS export
hosts: servera.lab.example.com
become: true
vars:
shared_dir: /nfsshare
mount_point: /datanfs
tasks:
- name: the nfs-utils package is installed
yum:
name: nfs-utils
state: present
- name: the NFS export is mounted and in /etc/fstab
mount:
path: "{{ mount_point }}"
src: serverd.lab.example.com:{{ shared_dir }}
state: mounted
fstype: nfs
nfs-utils
软件包:使用yum
模块确保目标主机上安装了nfs-utils
软件包。{{ shared_dir }}
)是否存在。如果目录不存在,则使用指定的所有者、组和权限创建该目录。templates/share.exports.j2
)生成NFS导出配置文件(/etc/exports.d/share.exports
)。该配置文件定义了要导出的目录以及访问权限等参数。导出配置文件的所有者、组和权限也被指定。nfs-server
服务:使用service模块启动并启用nfs-server服务,确保NFS服务器正在运行,并在系统启动时自动启用该服务。[student@workstation filestorage-automation]$ cat nfs_server.yml
---
- name: Export a directory using NFS
hosts: serverd.lab.example.com
become: true
vars:
shared_dir: /nfsshare
tasks:
- name: the nfs-utils package is installed
yum:
name: nfs-utils
state: present
- name: the directory exists
file:
path: "{{ shared_dir }}"
owner: student
group: root
mode: '0755'
state: directory
- name: the directory is exported
template:
src: templates/share.exports.j2
dest: /etc/exports.d/share.exports
owner: root
group: root
mode: '0644'
notify: reload exports
- name: the nfs-server service is started and enabled
service:
name: nfs-server
state: started
enabled: yes
- name: the nfs firewall service is opened
firewalld:
service: nfs
state: enabled
immediate: yes
permanent: yes
handlers:
- name: reload exports
service:
name: nfs-server
state: reloaded
[student@workstation filestorage-automation]$
生成NFS共享的导出配置文件
[student@workstation filestorage-automation]$ cat templates/share.exports.j2
{{ shared_dir }}{% for host in groups['clients'] %}
{{ host }}(rw)
{%- endfor %}
© 文中涉及参考链接内容版权归原作者所有,如有侵权请告知,这是一个开源项目,如果你认可它,不要吝啬星星哦 😃
红帽服务管理与自动化(RH358)
授课笔记
© 2018-2023 liruilonger@gmail.com, All rights reserved. 保持署名-非商用-相同方式共享(CC BY-NC-SA 4.0)