Removing Files and Replacing with links, IF it's a file

( Sorry if this is a repost, I can’t find the original as if it didn’t post )

I’m trying to build out some new Ubuntu machines. One of the things I want to do is remove /root/.bashrc, IF it’s a file and then create a link. Right now I’m using two tasks:

  • name: Remove /root files
    command: rm -f /root/{{ item.path }}
    with_items:

  • { path: ‘.bashrc’ }

  • { path: ‘.bash_profile’ }

  • name: Create Root profile links
    file:
    src: “/root/{{ item.path }}”
    dest: “/root/{{ item.dest }}”
    state: link
    with_items:

  • { path: ‘.profile’, dest: ‘.bash_profile’ }

  • { path: ‘.profile’, dest: ‘.bashrc’ }

The problem is any time this runs, it removes the 2 files then re-creates them, constant “changes” reported. Is there a better way to do this that will only remove .bashrc if it’s a file, actually if it’s not the link I want, then create it?

-R

As stated on the page for this list the first post is moderated.

(note: to avoid spam, initial posts to this group are moderated, but are approved pretty quickly)
https://groups.google.com/forum/#!forum/ansible-project

So you need to have some patience.