thanks kai, i got the stat to work in this way:

---
# make /tmp/link-dir--test a link.
# delete it if it already exists.

- hosts: localhost
  become: false
  vars:
    path__test_dir_link: /tmp/link-dir--test
  tasks:
    - name: check if dest is a link
      stat:
        path: "{{ path__test_dir_link }}"
      register: stat__path__test_dir_link
    - name: remove dest
      file:
        path: "{{ path__test_dir_link }}"
        state: absent
      when:
        - stat__path__test_dir_link['stat']['islnk'] is defined
        - stat__path__test_dir_link['stat']['islnk'] == false
    - name: create link
      file:
        dest: "{{ path__test_dir_link }}"
        src: /usr
        state: link

On Friday, February 17, 2017 at 6:39:09 PM UTC+11, Kai Stian Olstad wrote:
>
> On 17.02.2017 01:51, sunnz wrote: 
> > can ansible force a path to be a link even when it is a directory with 
> > files? currently i am deleting the directory before making it a link 
> > and it 
> > is not idempotent. 
>
> You can't force it, you need to delete and create link as you do now. 
>
> > 
> > on the first run it deletes the directory. but it is also deleting and 
> > re-creating the link in every run after that. 
>
> Before you delete and create link use the stat module to check if the 
> path is a directory and then do a delete and create the link. 
>
> https://docs.ansible.com/ansible/stat_module.html 
>
> -- 
> Kai Stian Olstad 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Ansible Project" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/ansible-project/2e7de3e3-1d69-4af7-babe-caf40b932036%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to