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


当前回答

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

你可以参考可靠的文档

其他回答

目录只能使用文件模块创建,因为目录只是一个文件。

# create a directory if it doesn't exist
- file:
    path: /etc/some_directory
    state: directory
    mode: 0755
    owner: foo
    group: foo

你可以使用陈述句

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

您需要文件模块。要创建目录,您需要指定选项状态:directory:

- name: Creates directory
  file:
    path: /src/www
    state: directory

你可以在https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html上看到其他选项

可以直接执行该命令,使用ansible直接创建

ansible -v targethostname -m shell -a "mkdir /srv/www" -u targetuser

OR

ansible -v targethostname -m file -a "path=/srv/www state=directory" -u targetuser

如果你想在windows中创建一个目录:

- name: create folder in Windows
  win_file:
    path: C:\Temp\folder\subfolder
    state: directory

有关更多信息,请参阅win_file模块。