你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
您需要文件模块。要创建目录,您需要指定选项状态:directory:
- name: Creates directory
file:
path: /src/www
state: directory
你可以在https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html上看到其他选项
其他回答
只需要为特定的分配设置执行任务的条件
- name: Creates directory
file: path=/src/www state=directory
when: ansible_distribution == 'Debian'
要检查目录是否存在,然后运行一些任务(例如创建目录),请使用以下命令
- name: Check if output directory exists
stat:
path: /path/to/output
register: output_folder
- name: Create output directory if not exists
file:
path: /path/to/output
state: directory
owner: user
group: user
mode: 0775
when: output_folder.stat.exists == false
我们有模块可以在ansible中创建目录,文件
例子
- name: Creates directory
file:
path: /src/www
state: directory
如果你想在windows中创建一个目录:
- name: create folder in Windows
win_file:
path: C:\Temp\folder\subfolder
state: directory
有关更多信息,请参阅win_file模块。
enter code here
- name: creating directory in ansible
file:
path: /src/www
state: directory
owner: foo
你可以参考可靠的文档