ansible copy directory code example

Example 1: copy folder ubuntu

$ cp -r /source_directory /destination_directory

Example 2: ansible create folder

- name: Create a directory if it does not exist
  ansible.builtin.file:
    path: /etc/some_directory
    state: directory
    mode: '0755'

Example 3: ansible copy

- name: Copy in config file for RHEL
  copy:
    src: './files/rhel/syslog'
    dest: '/etc/logrotate.d/'
    owner: root
    group: root
    mode: '0600'
  when:
    - ansible_facts['distribution'] == 'RedHat'
  become: yes