如何使用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`
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值