Ansible을 사용하여 디렉토리를 만드는 방법

Ansible 플레이 북을 사용하여 데비안 기반 시스템 www에서 디렉토리 를 어떻게 만드 /srv나요?



답변

파일 모듈이 필요합니다. 디렉토리를 작성하려면 다음 옵션을 지정해야합니다 state=directory.

- name: Creates directory
  file:
    path: /src/www
    state: directory

http://docs.ansible.com/file_module.html 에서 다른 옵션을 볼 수 있습니다


답변

파일 모듈을 확장하고 소유자, 그룹 및 권한을 설정할 수도 있습니다. (참고 : Ansible 파일 문서 )

- name: Creates directory
  file:
    path: /src/www
    state: directory
    owner: www-data
    group: www-data
    mode: 0775

디렉토리를 재귀 적으로 작성할 수도 있습니다.

- name: Creates directory
  file:
    path: /src/www
    state: directory
    owner: www-data
    group: www-data
    mode: 0775
    recurse: yes

이렇게하면 두 디렉토리가 존재하지 않으면 두 디렉토리가 모두 만들어집니다.


답변

다음을 사용하여 만들 수 있습니다.

최신 버전 2 <

- name: Create Folder
  file:
    path: /srv/www/
    owner: user
    group: user
    mode: 0755
    state: directory

이전 버전

- name: Create Folder
  file:
   path=/srv/www/
   owner=user
   group=user
   mode=0755
   state=directory

참조-http: //docs.ansible.com/ansible/file_module.html


답변

디렉토리는 파일 일 뿐이므로 파일 모듈 만 사용하여 디렉토리를 작성할 수 있습니다.

# create a directory if it doesn't exist
- file:
    path: /etc/some_directory
    state: directory
    mode: 0755
    owner: foo
    group: foo


답변

- file:
    path: /etc/some_directory
    state: directory
    mode: 0755
    owner: someone
    group: somegroup

이것이 실제로 권한, 소유자 및 그룹을 설정할 수있는 방법입니다. 마지막 세 매개 변수는 필수가 아닙니다.


답변

디렉토리를 만들 수 있습니다. 사용

# create a directory if it doesn't exist
- file: path=/src/www state=directory mode=0755

regaridng 디렉토리 및 파일 시스템에 대한 자세한 내용은 http://docs.ansible.com/ansible/file_module.html 을 참조
하십시오 .


답변

여기에 모든 답변에 추가로 하나 이상의 디렉토리를 만들어야하는 상황이 많으므로 각 디렉토리에 대해 별도의 작업을 만드는 대신 루프를 사용하는 것이 좋습니다.

- name: Creates directory
  file:
    path: "{{ item }}"
    state: directory
  with_items:
  - /srv/www
  - /dir/foo
  - /dir/bar