你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
如果你想在windows中创建一个目录:
- name: create folder in Windows
win_file:
path: C:\Temp\folder\subfolder
state: directory
有关更多信息,请参阅win_file模块。
其他回答
在本例中,您可以使用"file"模块,其中有许多参数可以传递给新创建的目录,如所有者、组、位置、模式等.....
关于文件模块的详细说明请参考本文档…
https://docs.ansible.com/ansible/latest/modules/file_module.html#file-module
记住这个模块不仅仅是用来创建目录的!!
创建目录
ansible host_name -m file -a "dest=/home/ansible/vndir state=directory"
我们有模块可以在ansible中创建目录,文件
例子
- name: Creates directory
file:
path: /src/www
state: directory
可以直接执行该命令,使用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
在这种情况下,您需要使用文件模块。下面的剧本,你可以使用你的参考。
---
- 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