[deyu1@kvm19 ansible]$ ansible-doc file
[deyu1@kvm19 ansible]$ ansible-doc file | grep ^EX -A7 EXAMPLES: - name: Change file ownership, group and permissions file: path: /etc/foo.conf owner: foo group: foo mode: '0644'
- name: Create an insecure file file: path: /work owner: root group: root mode: '1777'
- name: Create a symbolic link file: src: /file/to/link/to dest: /path/to/symlink owner: foo group: foo state: link
- name: Create two hard links file: src: '/tmp/{{ item.src }}' dest: '{{ item.dest }}' state: link loop: - { src: x, dest: y } - { src: z, dest: k }
- name: Touch a file, using symbolic modes to set the permissions (equivalent to 0644) file: path: /etc/foo.conf state: touch mode: u=rw,g=r,o=r
- name: Touch the same file, but add/remove some permissions file: path: /etc/foo.conf state: touch mode: u+rw,g-wx,o-rwx
- name: Touch again the same file, but dont change times this makes the task idempotent file: path: /etc/foo.conf state: touch mode: u+rw,g-wx,o-rwx modification_time: preserve access_time: preserve
- name: Create a directory if it does not exist file: path: /etc/some_directory state: directory mode: '0755'
- name: Update modification and access time of given file file: path: /etc/some_file state: file modification_time: now access_time: now
- name: Set access time based on seconds from epoch value file: path: /etc/another_file state: file access_time: '{{ "%Y%m%d%H%M.%S" | strftime(stat_var.stat.atime) }}'
- name: Recursively change ownership of a directory file: path: /etc/foo state: directory recurse: yes owner: foo group: foo