本文翻譯自: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`