您可以创建目录。运用
# 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目录和文件系统。
只需要设置条件来执行特定分配的任务
- name: Creates directory file: path=/src/www state=directory when: ansible_distribution == 'Debian'
创建目录
ansible host_name -m file -a "dest=/home/ansible/vndir state=directory"
这是更简单的方法。
- name: create dir command: mkdir -p dir dir/a dir/b
您甚至可以扩展文件模块,甚至可以设置所有者,组和&通过它的许可。 (参考: Ansible文件文档 )
- 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
这样,如果它们不存在,它将创建两个目录。
根据Ansible文档 ,可以通过定义以下内容来完成:
# create a directory if it doesn't exist - file: path: /etc/some_directory state: directory mode: 0755
我们有可用于创建目录的模块,文件在ansible中
例
- name: Creates directory file: path: /src/www state: directory
--- - 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中
欲了解更多信息,请告诉我。
您可以使用该声明
- name: webfolder - Creates web folder file: path=/srv/www state=directory owner=www-data group=www-data mode=0775`
- file: path: /etc/some_directory state: directory mode: 0755 owner: someone group: somegroup
这就是你实际上也可以设置权限,所有者和组的方式。最后三个参数不是强制性的。
你可以创建使用:
- 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
您可以直接运行该命令并使用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