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


当前回答

在这种情况下,您需要使用文件模块。下面的剧本,你可以使用你的参考。

    ---
     - 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 

其他回答

创建目录

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`
- file:
    path: /etc/some_directory
    state: directory
    mode: 0755
    owner: someone
    group: somegroup

这也是设置权限,所有者和组的方法。最后三个参数不是必须的。

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

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

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

这里有一个更简单的方法。

—name:创建dir mkdir -p dir dir/a dir/b