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

Symbolic links to directories are not handled correctly #7657

Closed
willthames opened this issue Jun 4, 2014 · 1 comment
Closed

Symbolic links to directories are not handled correctly #7657

willthames opened this issue Jun 4, 2014 · 1 comment
Labels
bug This issue/PR relates to a bug. P2 Priority 2 - Issue Blocks Release

Comments

@willthames
Copy link
Contributor

Issue Type:

Bug Report

Ansible Version:

ansible 1.7 (devel 74f20eb) last updated 2014/06/04 13:35:25 (GMT +1000)

Environment:

Fedora 20 but will happen for other Linux OSs at least

Summary:

This seems to be a result of 202ac68 - nominally fixes for #7515 and #7537.

The check for whether a symlink that exists points to the correct destination is incorrect if that destination is a directory.

Steps To Reproduce:

The following playbook reproduces the issue. It works fine the first time, but not the second time:

- hosts: localhost
  connection: local

  tasks:
    - name: create a directory
      action: file state=directory path=/tmp/this_is_a_dir

    - name: create a link to a directory
      action: file state=link src=/tmp/this_is_a_dir dest=/tmp/this_is_a_link
Expected Results:

The playbook is idemptotent

Actual Results:
[will@fedora ansible]$ ansible-playbook broken-links.yml -v

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

GATHERING FACTS *************************************************************** 
ok: [localhost]

TASK: [create a directory] **************************************************** 
ok: [localhost] => {"changed": false, "gid": 1000, "group": "will", "mode": "0775", "owner": "will", "path": "/tmp/this_is_a_dir", "secontext": "unconfined_u:object_r:user_tmp_t:s0", "size": 40, "state": "directory", "uid": 1000}

TASK: [create a link to a directory] ****************************************** 
failed: [localhost] => {"failed": true, "gid": 1000, "group": "will", "mode": "0777", "owner": "will", "path": "/tmp/this_is_a_link", "secontext": "unconfined_u:object_r:user_tmp_t:s0", "size": 18, "src": "/tmp/this_is_a_dir", "state": "link", "uid": 1000}
msg: src file does not exist, use "force=yes" if you really want to create the link: /tmp/this_is_a_link/this_is_a_dir

FATAL: all hosts have already failed -- aborting

PLAY RECAP ******************************************************************** 
           to retry, use: --limit @/home/will/broken-links.retry

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

Note that it's trying to create a link to /tmp/this_is_a_link/this_is_a_dir, rather than to /tmp/this_is_a_dir.

One reason might be that os.path.isdir is True for symlinks that point to directories. I did not expect that.

I suspect
https://github.com/ansible/ansible/blob/devel/library/files/file#L192
should have a not os.path.islink(path) too.

@jimi-c jimi-c added P2 labels Jun 4, 2014
@jimi-c jimi-c closed this as completed in 7483acd Jun 5, 2014
@jimi-c
Copy link
Member

jimi-c commented Jun 5, 2014

I agree, and have added that to the check on that line, which does appear to correct this issue. Thanks for reporting it, and let us know if you have any further problems related to this!

jimi-c added a commit that referenced this issue Jun 9, 2014
The os.path.isdir() returns True for symlinks that point to directories,
so we also need to check to make sure it's not a symlink too.

Fixes #7657
@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. P2 Priority 2 - Issue Blocks Release
Projects
None yet
Development

No branches or pull requests

3 participants