# Ansible sequence for creating soft link

**URL:** <https://forum.ansible.com/t/ansible-sequence-for-creating-soft-link/32498>\
**Category:** Ansible Project\
**Created:** [March 19, 2020, 5:34am UTC](https://forum.ansible.com/t/ansible-sequence-for-creating-soft-link/32498 "2020-03-19T05:34:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rakesh\_Parida](https://avatars.discourse-cdn.com/v4/letter/r/3ab097/32.png) [@Rakesh\_Parida](https://forum.ansible.com/u/Rakesh_Parida)\
**Post date:** [March 19, 2020, 5:34am UTC](https://forum.ansible.com/t/ansible-sequence-for-creating-soft-link/32498/1 "2020-03-19T05:34:06Z")

</div>

Hi ,

I have 3 directories in /tmp as follows:  
Test\_10.0.0  
Test\_11.0.0  
Test\_13.0.0

other directories in /tmp  
Test  
Prod  
Dev

Now i want to create soft link of

Test\_10.0.0 - Test  
Test\_11.0.0 - Prod  
Test\_13.0.0 - Dev

I want to create a playbook which does it.  
Can anybody help in this regard

---

<div class="post-metadata">

**Author:** ![racke](https://sea1.discourse-cdn.com/ansible/user_avatar/forum.ansible.com/racke/32/4767_2.png) [@racke](https://forum.ansible.com/u/racke)\
**Post date:** [March 19, 2020, 6:35am UTC](https://forum.ansible.com/t/ansible-sequence-for-creating-soft-link/32498/2 "2020-03-19T06:35:32Z")

</div>

> Hi ,
> 
> I have 3 directories in /tmp as follows:  
> Test\_10.0.0  
> Test\_11.0.0  
> Test\_13.0.0
> 
> other directories in /tmp  
> Test  
> Prod  
> Dev
> 
> Now i want to create soft link of
> 
> Test\_10.0.0 - Test  
> Test\_11.0.0 - Prod  
> Test\_13.0.0 - Dev
> 
> I want to create a playbook which does it.  
> Can anybody help in this regard

From the docs:

- name: Create a symbolic link  
&nbsp;&nbsp;file:  
&nbsp;&nbsp;&nbsp;&nbsp;src: /file/to/link/to  
&nbsp;&nbsp;&nbsp;&nbsp;dest: /path/to/symlink  
&nbsp;&nbsp;&nbsp;&nbsp;owner: foo  
&nbsp;&nbsp;&nbsp;&nbsp;group: foo  
&nbsp;&nbsp;&nbsp;&nbsp;state: link

Regards  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Racke

---

<div class="post-metadata">

**Author:** ![J111](https://avatars.discourse-cdn.com/v4/letter/j/50afbb/32.png) [@J111](https://forum.ansible.com/u/J111)\
**Post date:** [March 20, 2020, 5:55pm UTC](https://forum.ansible.com/t/ansible-sequence-for-creating-soft-link/32498/3 "2020-03-20T17:55:58Z")

</div>

```auto
Hi Rakesh,

```

```auto
I create the following play for you with a variable that you can loop and access the src and dest for the links. 

```

```auto
---
- name: create softlink
  hosts: servers
  gather_facts: off
  vars:
    sf_links:
      - src: /tmp/Test_10.0.0
        dest: /tmp/Test
      - src: /tmp/Test_11.0.0
        dest: /tmp/Prod
      - src: /tmp/Test_13.0.0
        dest: /tmp/Dev
  tasks:
    - name: create softlinks
      file:
        src: "{{item.src}}"
        dest: "{{item.dest}}"
        state: link
      loop: "{{sf_links}}"

```
