Ansible Module file
Jump to navigation
Jump to search
External
Internal
Overview
Manage file, directory and symlinks properties: create, set attributes, remove.
Examples
Create Directories
- name: create volume directories
file:
path: "/mnt/ebs0/{{ item }}"
state: directory
owner: root
with_items:
- "local-pv0"
- "local-pv1"
- "local-pv2"
when:
- inventory_hostname in groups['kube-node']
Create directories following an existing directory structure, provided under the <role-name>/files
Ansible configuration directory:
- name: Create a directory structure mirroring an existing directory structure, specified by <code>with_filetree</code>, where the "filetree" is relative to <code><role-name>/files</code>.
file:
path: "{{ ansible_env.TARGET_DIR }}/{{ item.path }}"
state: directory
mode: '{{ item.mode }}'
with_filetree: "dirA/dirB/"
when: item.state == 'directory'