Showing posts with label file. Show all posts
Showing posts with label file. Show all posts

Tuesday, February 22, 2022

EXAMPLES: Ansible -file Module

 


This is standalone because it is important and is usually utilized in real-life work. The file module in ansible deals with file/directory-related operations.

Reference (documentation): 

https://docs.ansible.com/ansible/latest/collections/ansible/builtin/file_module.html 

http://www.devopsworld.co.in/p/ansible-file-module.html

https://irfandevops.blogspot.com/2022/02/hidden-file-module-ansible.html

HIDDEN: File Module - Ansible

 

File Module

change file ownership, group and mode

- file:
    path: /etc/foo.conf
    owner: foo
    group: foo
     # when specifying mode using octal numbers, add a leading 0
     mode: 0644

- file:
    path: /work
    owner: root
    group: root
    mode: 01777

- file:
    src: /file/to/link/to
    dest: /path/to/symlink
    owner: foo
    group: foo
    state: link

- file:
    src: '/tmp/{{ item.src }}'
    dest: '{{ item.dest }}'
    state: link
  with_items:
    - { src: 'x', dest: 'y' }
    - { src: 'z', dest: 'k' }

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"

touch the same file, but add/remove some permissions

  - file:
      path: /etc/foo.conf
      state: touch
      mode: "u+rw,g-wx,o-rwx"

touch again the same file, but dont change times( this makes the task idempotents)

   - file:
      path: /etc/foo.conf
      state: touch
      mode: "u+rw,g-wx,o-rwx"
      modification_time: "preserve"
      access_time: "preserve"

create a directory if it doesn't exist

  - file:
      path: /etc/some_directory
      state: directory
      mode: 0755

updates modification and access time of given file

  - file:
      path: /etc/some_file
      state: file
      mode: 0755
      modification_time: now

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...