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


当前回答

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

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

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

其他回答

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

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

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

“本地主机ansible_connection=本地”

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

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

—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 

我看到很多Playbooks的例子,我想提到Adhoc命令的例子。

$ansible -i inventory -m file -a "path=/tmp/ directory state=directory(我们可以用touch代替directory来创建文件)

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

你可以参考可靠的文档