YJWANG

[Ansible] NFS 서버 구축 본문

91.IaC

[Ansible] NFS 서버 구축

왕영주 2021. 1. 20. 10:36

NFS Server 구성 Playbook


해당 playbook을 실행하면 지정한 node의 /data를 export 합니다.

사용법

# ansible-playbook -i <Inventory File> nfs_server.yaml 

Customization

# path 및 line을 변경하여 권한과 directory를 변경하세요

          - name: Create Exported Directory
            file:
                    path: /data
                    state: directory
                    mode: '0777'

            lineinfile:
                    path: /etc/exports
                    line: '/data *(rw,no_root_squash,sync)'

# hosts를 변경하여 다른 host에 실행하도록 하세요
  hosts: master01

결과

수행 결과 제일 아래 Task에 exportfs -v 명령어 실행 결과가 의도한 값이어야 합니다.

[root@kube62_deploy_0 nfs]# ansible-playbook -i /root/kubespray/inventory/mycluster/inventory.ini nfs_server.yaml 
[WARNING]: Invalid characters were found in group names but not replaced, use -vvvv to see details

PLAY [Generate NFS Server] ****************************************************************************************************

TASK [Gathering Facts] ********************************************************************************************************
ok: [master01]

TASK [Install Package] ********************************************************************************************************
changed: [master01]

TASK [Create Exported Directory] **********************************************************************************************
changed: [master01]

TASK [Edit Exports File] ******************************************************************************************************
changed: [master01]

TASK [Enable and Start NFS-Server] ********************************************************************************************
changed: [master01]

TASK [Print Export Status] ****************************************************************************************************
changed: [master01]

TASK [debug] ******************************************************************************************************************
ok: [master01] => {
    "exportfs_result.stdout": "/data         \t<world>(sync,wdelay,hide,no_subtree_check,sec=sys,rw,secure,no_root_squash,no_all_squash)"
}

Playbook

[root@kube62_deploy_0 nfs-server]# cat nfs_server.yaml 
---
- name: Generate NFS Server
  hosts: master01
  tasks:
          - name: Install Package
            yum:
                    name: nfs-utils
                    state: latest

          - name: Create Exported Directory
            file:
                    path: /data
                    state: directory
                    mode: '0777'

          - name: Edit Exports File
            lineinfile:
                    path: /etc/exports
                    line: '/data *(rw,no_root_squash,sync)'

          - name: Enable and Start NFS-Server
            systemd:
                    name: nfs-server
                    enabled: yes
                    state: started

          - name: Print Export Status
            shell:
                    cmd: exportfs -v
            register: exportfs_result

          - debug:
                  var: exportfs_result.stdout
반응형