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

**URL:** <https://forum.ansible.com/t/removing-files-and-replacing-with-links-if-its-a-file/23790>\
**Category:** Ansible Project\
**Tags:** ubuntu\
**Created:** [February 21, 2017, 5:21pm UTC](https://forum.ansible.com/t/removing-files-and-replacing-with-links-if-its-a-file/23790 "2017-02-21T17:21:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_L\_Harris](https://avatars.discourse-cdn.com/v4/letter/r/3bc359/32.png) [@Robert\_L\_Harris](https://forum.ansible.com/u/Robert_L_Harris)\
**Post date:** [February 21, 2017, 5:21pm UTC](https://forum.ansible.com/t/removing-files-and-replacing-with-links-if-its-a-file/23790/1 "2017-02-21T17:21:20Z")

</div>

( 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

---

<div class="post-metadata">

**Author:** ![Kai\_Stian\_Olstad](https://avatars.discourse-cdn.com/v4/letter/k/e19adc/32.png) [@Kai\_Stian\_Olstad](https://forum.ansible.com/u/Kai_Stian_Olstad)\
**Post date:** [February 22, 2017, 7:09pm UTC](https://forum.ansible.com/t/removing-files-and-replacing-with-links-if-its-a-file/23790/2 "2017-02-22T19:09:30Z")

</div>

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](https://groups.google.com/forum/#!forum/ansible-project)

So you need to have some patience.
