728x90

실습 개요


실습 목적

- 하나의 플레이북으로 두 개의 작업 진행

 

실습 과정

1. 앤서블 서버에 공유 디렉토리를 생성

2. 앤서블 노드들이 공유 디렉토리에 접근할 수 있도록 설정

 - 로컬 디렉토리처럼 사용

 

아키텍처

 

 

 


nfs.yml 파일 생성


  1 ---
  2 - name: Setup for nfs server
  3   gather_facts: no
  4   hosts: localhost
  5
  6   tasks:
  7     - name: make nfs_shared directory
  8       file:
  9         path: /home/vagrant/nfs_shared
 10         state: directory
 11         mode: 0777
 12
 13     - name: configure /etc/exports
 14       become: yes
 15       lineinfile:
 16         path: /etc/exports
 17         line: /home/vagrant/nfs_shared 172.30.1.0/24(rw,sync)
 18
 19     - name: nfs service restart
 20       become: yes
 21       service:
 22         name: nfs
 23         state: restarted
 24
 25
 26 - name: Setup for nfs clients
 27   gather_facts: no
 28   hosts: CentOS
 29
 30   tasks:
 31     - name: make nfs_client directory
 32       file:
 33         path: /home/vagrant/nfs
 34         state: directory
 35
 36     - name: mount point directory as client
 37       become: yes
 38       mount:
 39         name: /home/vagrant/nfs
 40         src: 172.30.1.100:/home/vagrant/nfs_shared
 41         fstype: nfs
 42         opts: nfsvers=3
 43         state: mounted

 

 

nfs 서버 설정 확인


플레이북 실행 전: 설정 사항 없음

[vagrant@ansible-server ~]$ cat /etc/exports
[vagrant@ansible-server ~]$
[vagrant@ansible-server ~]$ exportfs
exportfs: could not open /var/lib/nfs/.etab.lock for locking: errno 13 (Permission denied)

 

플레이북 실행 후: 각각의 노드의 /home/vagrant/nfs 경로에 호스트 이름으로 파일 생성

# ansible-node01
PS C:\HashiCorp\udemy-ansible> vagrant ssh ansible-node01
[vagrant@ansible-node01 ~]$ ls
nfs
[vagrant@ansible-node01 ~]$ cd nfs
[vagrant@ansible-node01 nfs]$ ls
[vagrant@ansible-node01 nfs]$ touch $HOSTNAME
[vagrant@ansible-node01 nfs]$ ls
ansible-node01

# ansible-node02
PS C:\HashiCorp\udemy-ansible> vagrant ssh ansible-node02
[vagrant@ansible-node02 ~]$ ls
nfs
[vagrant@ansible-node02 ~]$ cd nfs
[vagrant@ansible-node02 nfs]$ ls
ansible-node01
[vagrant@ansible-node02 nfs]$ touch $HOSTNAME
[vagrant@ansible-node02 nfs]$ ls
ansible-node01  ansible-node02

 

앤서블 서버의 공유 디렉토리에 마운트 확인: 앤서블 서버의 nfs 공유 디렉토리에서 파일 확인

[vagrant@ansible-server nfs_shared]$ ls
ansible-node01  ansible-node02
728x90

+ Recent posts