你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
只需要为特定的分配设置执行任务的条件
- name: Creates directory
file: path=/src/www state=directory
when: ansible_distribution == 'Debian'
其他回答
enter code here
- name: creating directory in ansible
file:
path: /src/www
state: directory
owner: foo
你可以参考可靠的文档
---
- hosts: all
connection: local
tasks:
- name: Creates directory
file: path=/src/www state=directory
上面的playbook将在/src路径下创建www目录。
在运行上面的剧本之前。请确保您的ansible主机连接应该设置,
“本地主机ansible_connection=本地”
应该出现在/etc/ansible/hosts中
如需更多信息,请与我联系。
如果你想在windows中创建一个目录:
- name: create folder in Windows
win_file:
path: C:\Temp\folder\subfolder
state: directory
有关更多信息,请参阅win_file模块。
使用文件模块创建一个目录,并使用命令“ansible-doc file”获取文件模块的详细信息
这里有一个选项“state”解释:
If directory, all immediate subdirectories will be created if they do not exist, since 1.7 they will be created with the supplied permissions. If file, the file will NOT be created if it does not exist, see the [copy] or [template] module if you want that behavior. If link, the symbolic link will be created or changed. Use hard for hardlinks. If absent, directories will be recursively deleted, and files or symlinks will be unlinked. Note that file will not fail if the path does not exist as the state did not change. If touch (new in 1.4), an empty file will be created if the path does not exist, while an existing file or directory will receive updated file access and modification times (similar to the way touch works from the command line).
我们有模块可以在ansible中创建目录,文件
例子
- name: Creates directory
file:
path: /src/www
state: directory