bash
cd /server/scripts
bash
mkdir roles-all
bash
cd roles-all
bash
mkdir role01
bash
cd role01
bash
touch top.yml
touch hosts
mkdir -p nfs-server/{files,templates,tasks,handlers} group_vars/all/
bash
# 目录详情
[root@m01 /server/scripts/roles-all/role01]# tree F
.
├── group_vars/
│ └── all/
├── hosts
├── nfs-server/
│ ├── files/
│ ├── handlers/
│ ├── tasks/
│ └── templates/
└── top.yml
7 directories, 2 files
创建tasks
bashvim nfs-server/tasks/main.yml
bash- name: 01. Installing nfs-utils,rpcbind yum: name: nfs-utils,rpcbind state: present tags: - 01. Install - name: 02. Modify the configuration file template: src: exports.j2 dest: /etc/exports backup: yes notify: - restart_nfs tags: - 02. Modify the configuration file - name: 03. Create a shared directory and set the owner file: path: "{{ nfs_server_dir }}" owner: "{{ nfs_user }}" group: "{{ nfs_user }}" state: directory tags: - 03. Create a shared directory and set the owner - name: 04. Start the server systemd: name: "{{ item }}" enabled: yes state: started loop: - rpcbind tags: - 04. Start the server
bashvim nfs-server/templates/exports.j2
bash# author: {{ author }} {{ nfs_server_dir }} 172.16.1.0/24(rw,all_squash)
bashvim group_vars/all/main.yml
bashauthor: CJoy nfs_server_dir: /backup-nfs nfs_user: nfsnobody
bashvim nfs-server/handlers/main.yml
bash--- - name: restart_nfs systemd: name: nfs enabled: yes state: restarted
bashvim top.yml
bash- hosts: web roles: - role: nfs-server
目录成型
bash
[root@m01 role01]# tree -F
.
├── group_vars/
│ └── all/
│ └── main.yml
├── hosts
├── nfs-server/
│ ├── files/
│ ├── handlers/
│ │ └── main.yml
│ ├── tasks/
│ │ └── main.yml
│ └── templates/
│ └── exports.j2
└── top.yml
7 directories, 6 files