2
votes

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

3
On top of that, Ansible fails if you end the dest: parameter value with /, but with different reason.techraf

3 Answers

1
votes

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
0
votes

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
votes

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.