Create link with specific owner/group

Viewed 346

I'm trying to create some symbolic links with a specific owner/group, but it's always created with owner=root and group=root. Why?

This is my code:

- name: Get the directories to create symbolic links
  find:
    paths: /myPath/
  register: result

- name: Creation of symbolic links 
  file:
    src: "{{ item.path }}" 
    dest: /Path_Dest/{{ item.path | basename }}
    owner: 'owner1'
    group: 'group1'
    state: link
  with_items: "{{ result.files }}"   

Note :

  • owner1 and group1 exist.
  • No error in Ansible log
1 Answers

If you do not specify follow=False, the symlink will be followed (because default is follow=True) and the ownership and group will be applied to destination path. Use:

- name: Creation of symbolic links 
  file:
    src: "{{ item.path }}" 
    dest: /Path_Dest/{{ item.path | basename }}
    owner: 'owner1'
    group: 'group1'
    state: link
    follow: False
  with_items: "{{ result.files }}"   
Related