你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?


当前回答

您可以使用以下方法创建:

最新版本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

其他回答

要检查目录是否存在,然后运行一些任务(例如创建目录),请使用以下命令

- name: Check if output directory exists
    stat:
    path: /path/to/output
    register: output_folder

- name: Create output directory if not exists
    file:
    path: /path/to/output
    state: directory
    owner: user
    group: user
    mode: 0775
    when: output_folder.stat.exists == false

您可以创建目录。使用

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

你也可以咨询 http://docs.ansible.com/ansible/file_module.html 有关目录和文件系统的进一步详细信息。

—name:创建目录 ansible.builtin.file: 路径:/etc/some_directory 状态:目录 模式:“0755”

创建目录

ansible host_name -m file -a "dest=/home/ansible/vndir state=directory"

你可以使用陈述句

- name: webfolder - Creates web folder
  file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`