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


当前回答

enter code here 
- name: creating directory in ansible
  file:
   path: /src/www
   state: directory
   owner: foo

你可以参考可靠的文档

其他回答

创建目录

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

你可以用以下方法之一来做这件事:

例1:如果父目录已经存在:

- name: Create a new directory www at given path 
  ansible.builtin.file:
    path: /srv/www/
    state: directory
    mode: '0755'

例2:父目录不存在:

- name: Create a new directory www at given path recursively
  ansible.builtin.file:
    path: /srv/www/
    state: directory
    mode: '0755'
    recurse: yes

在示例2中,如果两个目录都不存在,它将递归地创建它们。

有关file_module的更多信息,您可以查看官方文档

您可以创建目录。使用

# 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: webfolder - Creates web folder
  file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
enter code here 
- name: creating directory in ansible
  file:
   path: /src/www
   state: directory
   owner: foo

你可以参考可靠的文档