Ansible sequence for creating soft link

16 views
Skip to first unread message

Rakesh Parida

unread,
Mar 19, 2020, 1:34:06 AM3/19/20
to Ansible Project
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

Stefan Hornburg (Racke)

unread,
Mar 19, 2020, 2:35:58 AM3/19/20
to ansible...@googlegroups.com
From the docs:

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

Regards
Racke

> --
> 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
> ansible-proje...@googlegroups.com <mailto:ansible-proje...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/ansible-project/7fe98ae3-4fc6-452f-bd2b-79121dd651e2%40googlegroups.com
> <https://groups.google.com/d/msgid/ansible-project/7fe98ae3-4fc6-452f-bd2b-79121dd651e2%40googlegroups.com?utm_medium=email&utm_source=footer>.


--
Ecommerce and Linux consulting + Perl and web application programming.
Debian and Sympa administration. Provisioning with Ansible.

signature.asc

J

unread,
Mar 20, 2020, 1:56:25 PM3/20/20
to ansible...@googlegroups.com
Hi Rakesh,
I create the following play for you with a variable that you can loop and access the src and dest for the links. 
---
- 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}}"

--
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 ansible-proje...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ansible-project/7fe98ae3-4fc6-452f-bd2b-79121dd651e2%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages