你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
如果你想在windows中创建一个目录:
- name: create folder in Windows
win_file:
path: C:\Temp\folder\subfolder
state: directory
有关更多信息,请参阅win_file模块。
其他回答
只需要为特定的分配设置执行任务的条件
- name: Creates directory
file: path=/src/www state=directory
when: ansible_distribution == 'Debian'
您需要文件模块。要创建目录,您需要指定选项状态: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
这里有一个更简单的方法。
—name:创建dir mkdir -p dir dir/a dir/b
目录只能使用文件模块创建,因为目录只是一个文件。
# create a directory if it doesn't exist
- file:
path: /etc/some_directory
state: directory
mode: 0755
owner: foo
group: foo