如何使用Ansible playbook在基于Debian的系统上在 /srv 创建目录 www ?
/srv
www
你想要文件模块 . 要创建目录,您需要指定选项 state=directory :
state=directory
- name: Creates directory file: path: /src/www state: directory
你可以在http://docs.ansible.com/file_module.html看到其他选项
您甚至可以扩展文件模块,甚至可以通过它设置所有者,组和权限 .
- name: Creates directory file: path: /src/www state: directory owner: www-data group: www-data mode: 0775
甚至,您可以递归地创建目录:
- name: Creates directory file: path: /src/www state: directory owner: www-data group: www-data mode: 0775 recurse: yes
这样,如果它们不存在,它将创建两个目录 .
你可以创建使用:
- 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
目录只能使用文件模块创建,因为目录只是一个文件 .
# create a directory if it doesn't exist - file: path: /etc/some_directory state: directory mode: 0755 owner: foo group: foo
-Jayesh
您可以创建目录 . 运用
# create a directory if it doesn't exist - file: path=/src/www state=directory mode=0755
您还可以参考http://docs.ansible.com/ansible/file_module.html了解更多详细信息regaridng目录和文件系统 .
- file: path: /etc/some_directory state: directory mode: 0755 owner: someone group: somegroup
这就是你实际上也可以设置权限,所有者和组的方式 . 最后三个参数不是强制性的 .
您可以使用该声明
- name: webfolder - Creates web folder file: path=/srv/www state=directory owner=www-data group=www-data mode=0775
只需要设置条件来执行特定分配的任务
- name: Creates directory file: path=/src/www state=directory when: ansible_distribution == 'Debian'
According to the Ansible documentation,可以通过定义以下内容来完成:
#如果目录不存在,则创建一个目录
--- - hosts: all connection: local tasks: - name: Creates directory file: path=/src/www state=directory
上面的playbook将在/ src路径中创建www目录 .
在运行上面的剧本之前 . 请确保您的ansible主机连接已设置,
“localhost ansible_connection = local”
应存在于/ etc / ansible / hosts中
欲了解更多信息,请告诉我 .
您可以直接运行该命令并使用ansible直接创建
ansible -v targethostname -m shell -a "mkdir /srv/www" -u targetuser
要么
ansible -v targethostname -m file -a "path=/srv/www state=directory" -u targetuser
这是更简单的方法 .
- name: create dir command: mkdir -p dir dir/a dir/b
12 回答
你想要文件模块 . 要创建目录,您需要指定选项
state=directory
:你可以在http://docs.ansible.com/file_module.html看到其他选项
您甚至可以扩展文件模块,甚至可以通过它设置所有者,组和权限 .
甚至,您可以递归地创建目录:
这样,如果它们不存在,它将创建两个目录 .
你可以创建使用:
最新版本2 <
旧版本
参考 - http://docs.ansible.com/ansible/file_module.html
目录只能使用文件模块创建,因为目录只是一个文件 .
-Jayesh
您可以创建目录 . 运用
您还可以参考http://docs.ansible.com/ansible/file_module.html了解更多详细信息regaridng目录和文件系统 .
- file: path: /etc/some_directory state: directory mode: 0755 owner: someone group: somegroup
这就是你实际上也可以设置权限,所有者和组的方式 . 最后三个参数不是强制性的 .
您可以使用该声明
- name: webfolder - Creates web folder file: path=/srv/www state=directory owner=www-data group=www-data mode=0775
只需要设置条件来执行特定分配的任务
According to the Ansible documentation,可以通过定义以下内容来完成:
path:/ etc / some_directory
state:目录
模式:0755
上面的playbook将在/ src路径中创建www目录 .
在运行上面的剧本之前 . 请确保您的ansible主机连接已设置,
“localhost ansible_connection = local”
应存在于/ etc / ansible / hosts中
欲了解更多信息,请告诉我 .
您可以直接运行该命令并使用ansible直接创建
要么
这是更简单的方法 .
- name: create dir command: mkdir -p dir dir/a dir/b