Ansible

Ansible Module - File

코딩+아빠 2023. 6. 27. 20:03

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html#file-module

 

ansible.builtin.file module – Manage files and file properties — Ansible Documentation

The permissions the resulting filesystem object should have. For those used to /usr/bin/chmod remember that modes are actually octal numbers. You must give Ansible enough information to parse them correctly. For consistent results, quote octal numbers (for

docs.ansible.com

- name: create apps directory
  file:
  path: "{{ apps_directory }}"
  state: directory/touch/link

State

state
  • Choices:
  • absent
  • directory
  • file ← default
  • hard
  • link
  • touch

absent : 디렉토리를 recursive하게 삭제한다. 심볼링 링크도 삭제한다.
directory : 디렉토리가 존재하지 않는 경우 생성(recursively)
file : 파일 소유자, 그룹, 모드를 변경하는 등의 작업을 할 수 있다. 파일이 존재하지 않으면 생성되지 않는다.
hard : 하드 링크를 생성한다.
link : 심볼릭 링크를 생성한다.
touch : 리눅스 touch 명령어와 유사하다.

- name: 'create myfile.txt'
  hosts: web1
  tasks:
  - name: 'create myfile.txt on web1'
    file:
      path: /root/myfile.txt
      state: touch
반응형