3

Error:

FAILED! => {"changed": false, "failed": true, "gid": 0, "group": "root", "mode": "0755", "msg": "the directory /var/www/html/simpleRepoTwo/simpleRepoThree/release-20161213-1927/ is not empty, refusing to convert it", "owner": "root", "path": "/var/www/html/simpleRepoTwo/simpleRepoThree/release-20161213-1927/", "size": 4096, "state": "directory", "uid": 0}

i've also tried creating symlink in /home/ubuntu/ with different directories. force:yes did not work.

Here is the code

- name: Creating symlinks of Products
  file:
    src: /home/ubuntu/productName/
    dest: /var/www/html/simpleRepoTwo/simpleRepoThree/release-{{release_folder}}/
    state: link
    force: yes

I want to create symlink of productName inside simpleRepoTwo/simpleRepoThree/release-20161213-1927

1
  • On top of that, Ansible fails if you end the dest: parameter value with /, but with different reason.
    – techraf
    Dec 14, 2016 at 2:00

3 Answers 3

3

To create a symlink "/home/ubuntu/productName" to your folder "/var/www/html/simpleRepoTwo/simpleRepoThree/release-{{release_folder}}", you must set "/home/ubuntu/productName" in your parameter dest. Final '/' must not be used

About force parameter, use it in two cases:

  • the source file does not exist (but will appear later)
  • destination exists and is a file (so, we need to unlink the "path" file and create symlink to the "src" file in place of it).

Use this task

- name: Creating symlinks of Products
  file:
    src: /var/www/html/simpleRepoTwo/simpleRepoThree/release-{{release_folder}}
    dest: /home/ubuntu/productName
    state: link

To loop over items, use this task

- name: Creating symlinks of Products
  file:
    src: "/var/www/html/simpleRepoTwo/simpleRepoThree/release-{{ release_folder }}/{{ item.src }}"
    dest: "/home/ubuntu/{{ item.dest }}"
    state: link
  with_items:
  - src: p1
    dest: p1
  - src: p2
    dest: p2
4
  • Hello @Nelson G, symlink was created, but then again i tried to loop it, since we have around 8 products, so when user types ourwebsite.com/admin it will land in adminpanel.
    – Shirshak
    Dec 14, 2016 at 6:51
  • - name: Creating symlinks of Products file: src: '/var/www/html/{{ item.src }}/' dest: '/var/www/html/simpleRepoTwo/simpleRepoThree/{{release_folder}}/{{ item.dest }}' state: link with_items: - { src: 'simpleRepo', dest: 'prodcutOne' } - { src: 'simpleRepo', dest: 'prodcutTwo' } - { src: 'simpleRepo', dest: 'prodcutThree' } - { src: 'simpleRepo', dest: 'prodcutFour' }
    – Shirshak
    Dec 14, 2016 at 6:54
  • Hello Nelson and tecraf, i tired to create symlinks using loops, both the syntax did not work. Here's gist. gist.github.com/shirshakparakhi/… Error(pretty print):: failed:[ 54.85 .157.222 ](item={ u'dest':u'prodcutSix', u'src':u'simpleRepo' }) =>{ "failed":true, "item":{ "dest":"prodcutSix", "src":"simpleRepo" }, "msg":"Error while linking: [Errno 2] No such file or directory", "path":"/var/www/html/simpleRepoTwo/simpleRepoThree/20161214-1334/prodcutSix", "state":"absent" }
    – Shirshak
    Dec 14, 2016 at 7:54
  • If i run playbook in intervals, 8 product symlinks are not created evenly, sometimes it throws error, sometimes it just creates symlinks perfectly. But most of the time its just error: Error:: (item={u'dest': u'prodcutTwo', u'src': u'simpleRepo'}) => {"failed": true, "item": {"dest": "prodcutTwo", "src": "simpleRepo"}, "msg": "Error while linking: [Errno 2] No such file or directory", "path": "/var/www/html/simpleRepoTwo/simpleRepoThree/20161214-1540/prodcutTwo", "state": "absent"}
    – Shirshak
    Dec 14, 2016 at 10:09
1

There seems to be no way to do what you require.

An empty directory can be "converted" into a symbolic link within another directory.This "conversion" requires the removal of the original directory and the subsequent creation of a symbolic link.

But if that directory isn't empty, the directory removal would make all of its content unavailable altogether. And Ansible says that's not possible as clearly stated in the error message.

Of course, you can create a couple of tasks to first remove the directory content, then to "convert" it into a symbolic link.

0

If this is a rails application, rails puts a .keep file in some folders. Log for example. This causes a folder to not be empty. Empty the folder then try again.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.