1
votes

I've been trying to create symlinks of 8 different products in a single Ansible task. Here is my code.

- name: Other 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:  p1
  - src:  simpleRepo
    dest:  p2
  - src:  simpleRepo
    dest:  p3
  - src:  simpleRepo
    dest:  p4
  - src:  simpleRepo
    dest:  p5
  - src:  simpleRepo
    dest:  p6
  - src:  simpleRepo
    dest:  p7
  - src:  simpleRepo
    dest:  p8

Error:

(item={u'dest': u'p3', u'src': u'simpleRepo'}) => {"failed": true, "gid": 0, "group": "root", "item": {"dest": "p3", "src": "simpleRepo"}, "mode": "0755", "msg": "refusing to convert between directory and link for /var/www/html/simpleRepoTwo/simpleRepoThree/20161214-2004/p3", "owner": "root", "path": "/var/www/html/simpleRepoTwo/simpleRepoThree/20161214-2004/p3", "size": 4096, "state": "directory", "uid": 0}

Error 2

failed: [54.85.157.222] (item={u'dest': u'p8', u'src': u'simpleRepo'}) => {"failed": true, "item": {"dest": "p8", "src": "simpleRepo"}, "msg": "Error while linking: [Errno 2] No such file or directory", "path": "/var/www/html/simpleRepoTwo/simpleRepoThree/20161214-2005/p8", "state": "absent"}

And here are the contents list /var/www/html/simpleRepo has just index.html and /var/www/html/simpleRepoTwo/simpleRepoThree/ has release folder based on timestmp 20161214-1922 , 20161214-1921, /var/www/html/simpleRepoTwo/simpleRepoThree/20161214-1922/ should have p1, p2 symlinks which point to p1 -> /var/www/html/simpleRepo

I tried creating all the folders first and symlinking simpleRepo. Also, i used the command module, changed the directory. Like this. Still, creating symlink is unstable.

 - command: ln -s /var/www/html/simpleRepo /var/www/html/simpleRepoTwo/simpleRepoThree/{{release_folder}}/p2
   args:
     chdir: /var/www/html/simpleRepoTwo/simpleRepoThree/{{release_folder}}/

Thanks in advance.

1
And here are the contents, also updated the question by including the Ansible transcript /var/www/html/simpleRepo has just index.html and /var/www/html/simpleRepoTwo/simpleRepoThree/ has release folder based on timestmp 20161214-1922 , 20161214-1921 and /var/www/html/simpleRepoTwo/simpleRepoThree/20161214-1922/ should have productOne, productTwo symlinks which point to productOne -> /var/www/html/simpleRepo - Shirshak
@techraf, yes, all the directories are present. - Shirshak
Hello, techraf, thanks for pointing out. I've corrected the mistakes, included task and contents. Where am i wrong? - Shirshak
Hello, techraf, thanks for not answering. I figured the solution. The problem was on creating folder based on timestamp. On change of timestamp, different folders would create. Hence the issue. - Shirshak

1 Answers

0
votes

In case it helps anyone else, I got the same error message:

refusing to convert between directory and link for /path/to/file

Because an earlier task in my playbook had created a directory with the same name as the link that I was trying to create in dest.