你如何创建一个目录www在/srv上基于debian的系统使用Ansible剧本?
当前回答
- file:
path: /etc/some_directory
state: directory
mode: 0755
owner: someone
group: somegroup
这也是设置权限,所有者和组的方法。最后三个参数不是必须的。
其他回答
创建目录
ansible host_name -m file -a "dest=/home/ansible/vndir state=directory"
你可以使用陈述句
- name: webfolder - Creates web folder
file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
这里有一个更简单的方法。
—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
---
- hosts: all
connection: local
tasks:
- name: Creates directory
file: path=/src/www state=directory
上面的playbook将在/src路径下创建www目录。
在运行上面的剧本之前。请确保您的ansible主机连接应该设置,
“本地主机ansible_connection=本地”
应该出现在/etc/ansible/hosts中
如需更多信息,请与我联系。