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


当前回答

---
- hosts: all
  connection: local
  tasks:
    - name: Creates directory
      file: path=/src/www state=directory

上面的playbook将在/src路径下创建www目录。

在运行上面的剧本之前。请确保您的ansible主机连接应该设置,

“本地主机ansible_connection=本地”

应该出现在/etc/ansible/hosts中

如需更多信息,请与我联系。

其他回答

我们有模块可以在ansible中创建目录,文件

例子

- name: Creates directory
  file:
    path: /src/www
    state: directory
enter code here 
- name: creating directory in ansible
  file:
   path: /src/www
   state: directory
   owner: 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上看到其他选项

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

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