- name: Ensure permissions are correct
  become: yes
  block:
    - name: Ensure user ownership
      ansible.builtin.command: find {{ jfrog_home_directory }} ! -user {{ artifactory_user }} -print -exec chown {{ artifactory_user }} {} \;
      register: user_ownerships
      changed_when: user_ownerships.stdout_lines | length > 0

    - name: Ensure group ownership
      ansible.builtin.command: find {{ jfrog_home_directory }} ! -group {{ artifactory_group }} -print -exec chgrp {{ artifactory_group }} {} \;
      register: group_ownerships
      changed_when: user_ownerships.stdout_lines | length > 0
