파이문

[Ansible] 디렉토리 생성 하기 본문

TIL

[Ansible] 디렉토리 생성 하기

민Z 2020. 9. 17. 18:26

서버에 환경 설정 배포할 일이 있는데 그동안 ssh 나 fabric 이나 이런것들로만 하다가 ansible 을 써보기로 했다. (ansible 1일차)

test 란 유저로 /path/to/test 란 디렉토리를 생성하는 예제이다. (become 옵션을 yes 로 하면 sudo 권한을 준 것과 같다.)

#
#
# 디렉토리 생성 예제
#
#
- hosts: tester
  remote_user: test
  tasks:
  - name: Create a test1 directory if it does not exist
    become: yes
    file:
      owner: test
      group: test
      path: /path/to/test1
      state: directory
      mode: 0755

hosts 란 키 값에 tester 를 넣었다. 실행할 때 인벤토리 옵션으로 tester 란 키를 가진 hosts 파일 정보를 넘겨야 한다. hosts 파일이 아래와 같이 생겨야 하고 (경로는 /path/to/hosts/sample)

[tester]
some-example-host.com

실행할 땐 요렇게 주면 된다.

ansible-playbook create_default_dir.yml -i /path/to/hosts/sample

 

Comments