你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
您可以创建目录。使用
# create a directory if it doesn't exist
- file: path=/src/www state=directory mode=0755
你也可以咨询 http://docs.ansible.com/ansible/file_module.html 有关目录和文件系统的进一步详细信息。
其他回答
您可以创建目录。使用
# create a directory if it doesn't exist
- file: path=/src/www state=directory mode=0755
你也可以咨询 http://docs.ansible.com/ansible/file_module.html 有关目录和文件系统的进一步详细信息。
如果你想在windows中创建一个目录:
- name: create folder in Windows
win_file:
path: C:\Temp\folder\subfolder
state: directory
有关更多信息,请参阅win_file模块。
另外,在很多情况下,您需要创建多个目录,因此使用循环而不是为每个目录创建单独的任务是一个好主意。
- name: creates multiple directories in one task
file:
path: "{{ item }}"
state: directory
loop:
- /srv/www
- /dir/foo
- /dir/bar
—name:创建目录 ansible.builtin.file: 路径:/etc/some_directory 状态:目录 模式:“0755”
在这种情况下,您需要使用文件模块。下面的剧本,你可以使用你的参考。
---
- hosts: <Your target host group>
name: play1
tasks:
- name: Create Directory
files:
path=/srv/www/
owner=<Intended User>
mode=<Intended permission, e.g.: 0750>
state=directory