Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

file module: symlink error #7627

Closed
srgvg opened this issue Jun 1, 2014 · 12 comments · Fixed by #7676
Closed

file module: symlink error #7627

srgvg opened this issue Jun 1, 2014 · 12 comments · Fixed by #7676
Labels
bug This issue/PR relates to a bug. needs_info This issue requires further information. Please answer any outstanding questions.

Comments

@srgvg
Copy link
Contributor

srgvg commented Jun 1, 2014

Issue Type:

Bug Report: file module, state link got broken some time ago.

I'm not sure what more exactly triggers this. As this seems such intrusive, I'm flabbergasted it didn't got discovered or mentioned earlier.

Ansible Version:
  • Good in 1.5.5
  • Bad in 1.6.0 + devel
  • Broken since 2d25577 (according to git bisect between 1.5.5 and 1.6.0, cc: @bcoca)
Environment:

Ubuntu 13.10 but probably N/A

Summary:

Making a basic symlink without any extra options got broken in 1.6

Steps To Reproduce:
[A] serge@cyberlab:~/tmp$ ls -l
total 4
-rw-rw-r-- 1 serge serge 128 jun  1 20:41 play
-rw-rw-r-- 1 serge serge   0 jun  1 20:30 source
[A] serge@cyberlab:~/tmp$ cat play 

---
- hosts: localhost
  gather_facts: false
  tasks:
  - file:
      src: ./source
      dest: ./destination
      state: link
Expected Results:

with ansible/release1.6.0

[A] serge@cyberlab:~/tmp$ ansible-playbook -i localhost,  play 

PLAY [localhost] ************************************************************** 

TASK: [file ] ***************************************************************** 
changed: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=1    unreachable=0    failed=0 
Actual Results:

with ansible/release1.5.5:

[A] serge@cyberlab:~/tmp$ ansible-playbook -i localhost,  play 

PLAY [localhost] ************************************************************** 

TASK: [file ] ***************************************************************** 
failed: [localhost] => {"failed": true, "path": "./destination", "src": "./source", "state": "absent"}
msg: src file does not exist

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/serge/play.retry

localhost                  : ok=0    changed=0    unreachable=0    failed=1   
@mpdehaan mpdehaan changed the title file module: making a symlink is broken file module: making a symlink is broken (edit: relative symlink) Jun 1, 2014
@mpdehaan
Copy link
Contributor

mpdehaan commented Jun 1, 2014

In queue for reproduction.

I suspect most people are creating symlinks with full paths, rather than relative symlinks, or there's another scenario afoot.

However, it should be noted that there ARE integration tests for symlink creation in Ansible

What would probably be most helpful is to add a test that duplicates your problem here:

https://github.com/ansible/ansible/blob/devel/test/integration/roles/test_file/tasks/main.yml

@mpdehaan
Copy link
Contributor

mpdehaan commented Jun 1, 2014

This appears to be your problem

  src: ./source
  dest: ./destination

Not sure how this is expected to work when both the source and dest are relative.

@mpdehaan mpdehaan added P3 and removed P2 labels Jun 1, 2014
@mpdehaan mpdehaan changed the title file module: making a symlink is broken (edit: relative symlink) file module: symlink error when both src and dest are relative Jun 1, 2014
@srgvg
Copy link
Contributor Author

srgvg commented Jun 1, 2014

Hm, there's always a basedir that handles relative paths. As showed, in 1.5.5 that does work.
But actually the relative stuff is just for this test playbook, in my production case, I got the error with all absolute paths.

failed: [vega] => {"failed": true, "item": "", "path": "/home/seafile/ginsys/ccnet/mykey.peer", "src": "/home/seafile/ginsys/lib/ccnet/mykey.peer", "state": "absent"}
msg: src file does not exist, use "force=yes" if you really want to create the link: /home/seafile/ginsys/ccnet/mykey.peer

And, yes, "/home/seafile/ginsys/lib/ccnet/mykey.peer" existed.

@srgvg srgvg changed the title file module: symlink error when both src and dest are relative file module: symlink error Jun 1, 2014
@srgvg
Copy link
Contributor Author

srgvg commented Jun 1, 2014

Here is the updated play with absolute paths, same error:

[A] serge@cyberlab:~/tmp$ cat play; ll; ansible-playbook -i localhost,  play -v
---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - file:
      src: ~/tmp/source
      dest: ~/tmp/destination
      state: link
total 4,0K
-rw-rw-r-- 1 serge serge 156 jun  1 21:24 play

PLAY [localhost] ************************************************************** 

TASK: [file ] ***************************************************************** 
failed: [localhost] => {"failed": true, "path": "/home/serge/tmp/destination", "src": "/home/serge/tmp/source", "state": "absent"}
msg: src file does not exist, use "force=yes" if you really want to create the link: /home/serge/tmp/source

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/serge/play.retry

localhost                  : ok=0    changed=0    unreachable=0    failed=1   

Notice the "state": "absent" in the result, whilst the module was called with "state": "link"}.

@bcoca
Copy link
Member

bcoca commented Jun 1, 2014

what version? this was broken for a while but we fixed it. i just tested in latest dev:

---
- hosts: localhost
  connection: local
  gather_facts: false
  tasks:
  - file:
      src: ~/tmp/source
      dest: ~/tmp/destination
      state: link

and got this:

ansible-playbook test.yml -i 'localhost,'

PLAY [localhost] ************************************************************** 

TASK: [file ] ***************************************************************** 
changed: [localhost]

PLAY RECAP ******************************************************************** 
localhost                  : ok=1    changed=1    unreachable=0    failed=0   

and i checked:

ls -l tmp/
total 0
lrwxrwxrwx 1 bcoca bcoca 22 Jun  1 15:53 destination -> /home/bcoca/tmp/source
-rw-r--r-- 1 bcoca bcoca  0 Jun  1 15:50 source

@edrozenberg
Copy link
Contributor

Sounds related to #7515

Solution that works for me at the moment - note force must be set to 'yes' otherwise an error will be generated and the symlink will not be created.

- name: make relative symlink
  file: >
      src=relative_source_item_name
      dest=/full/path/and/name/to/link/to/be/created/mylink
      state=link
      force=yes

Example:

- name: make relative symlink
  file: >
      src=linux-3.14.4
      dest=/usr/src/linux
      state=link
      force=yes

@jsabo
Copy link

jsabo commented Jun 1, 2014

I ran into this today too.

@Xerkus
Copy link
Contributor

Xerkus commented Jun 4, 2014

Absolute and relative path links do not work for me on devel, unless force=true is used

jimi-c added a commit to jimi-c/ansible that referenced this issue Jun 5, 2014
@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2014

I have created the above patch to resolve this, if you'd like to test it. I've run it against the sample play you've included and it resolves the issue there.

@srgvg
Copy link
Contributor Author

srgvg commented Jun 5, 2014

@bcoca I had problems to reproduce it myself, until I noticed, the fault is over SSH only, not with connection local (must have been a paste error in my example playbook.)

Now I can confirm the bug triggers

  • not in 1.5.5
  • not in 1.6.0
  • does in 1.6.2
  • not in latest devel 11b72df and also not in @jimi-c 's patch at 43f96a6

Between 1.6.0 and 1.6.2 it was introduced by 1248d2c, which is a cherry pick of 062e829 in 1.7-devel, after which the bug existed in devel too.

But that was fixed by 202ac68 I see now.

By now I'm not sure what James` latest patch solved, but I could reproduce an error with this playbook:

- hosts: localhost                                                              
  gather_facts: false                                                           
  tasks:                                                                        
  - file:                                                                       
      src: source                                                               
      dest: destination                                                         
      state: link   

On devel, this fails both with -c ssh and -c local.
WIth James' patch, this works with -c local and still fails with -c ssh.

Though, that is normal, as my test files live in ~/tmp. If I move them to ~, it also works with -c ssh!

So this seems very OK with me :)

@bcoca
Copy link
Member

bcoca commented Jun 5, 2014

my testing is always with -c local, so this shows the flaw with that. This
weekend I'll have some time and I'll try to finalize a bunch of tests I was
adding for corner cases with symlinks.

@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2014

I've gone ahead and merged this in. Please let us know if you continue seeing any problems regarding this issue. Thanks!

jimi-c added a commit that referenced this issue Jun 9, 2014
@ansibot ansibot added bug This issue/PR relates to a bug. and removed bug_report labels Mar 6, 2018
@ansible ansible locked and limited conversation to collaborators Apr 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug This issue/PR relates to a bug. needs_info This issue requires further information. Please answer any outstanding questions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants