如何使用Ansible创建目录

本文翻译自:How to create a directory using Ansible

您如何使用Ansible剧本在基于Debian的系统上的/srv上创建目录www


#1楼

参考:https://stackoom.com/question/1Xr0D/如何使用Ansible创建目录


#2楼

You want the file module. 您需要文件模块。 To create a directory, you need to specify the option state=directory : 要创建目录,您需要指定选项state=directory

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

You can see other options at http://docs.ansible.com/file_module.html 您可以在http://docs.ansible.com/file_module.html上看到其他选项


#3楼

You can even extend the file module and even set the owner,group & permission through it. 您甚至可以扩展文件模块,甚至可以通过它设置所有者,组和权限。 (Ref: Ansible file documentation ) (参考: Ansible文件文档

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

Even, you can create the directories recursively: 甚至,您也可以递归创建目录:

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

This way, it will create the both directories, if they didn't exist. 这样,它将创建两个目录(如果它们不存在)。


#4楼

You can create a directory. 您可以创建一个目录。 using 使用

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

You can also consult http://docs.ansible.com/ansible/file_module.html for further details regaridng directory and file system. 您也可以访问http://docs.ansible.com/ansible/file_module.html,以获取有关重新创建目录和文件系统的更多详细信息。


#5楼

you can create using: 您可以使用以下方法创建:

Latest version 2< 最新版本2 <

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

Older version 旧版

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

Refer - http://docs.ansible.com/ansible/file_module.html 请参阅-http: //docs.ansible.com/ansible/file_module.html


#6楼

You can use the statement 您可以使用以下语句

- name: webfolder - Creates web folder
  file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章