使用Ansible创建本地目录(主机)可以通过使用file
模块实现。以下是一个示例代码:
- name: 创建本地目录
hosts: localhost
gather_facts: false
tasks:
- name: 创建目录
file:
path: /path/to/directory
state: directory
mode: 0755
在上面的示例中,我们使用file
模块创建了一个名为/path/to/directory
的目录。state
参数设置为directory
表示创建一个目录。mode
参数设置为0755
表示设置目录的权限为755。
要运行上面的示例,可以将代码保存为一个名为create_directory.yml
的文件,并使用以下命令运行:
ansible-playbook create_directory.yml
确保将/path/to/directory
替换为您希望创建的目录的实际路径。
上一篇:Ansible持久连接