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

The module file changes the relative path of a symlink to absolute #65448

Closed
robertdebock opened this issue Dec 3, 2019 · 3 comments · Fixed by #73700
Closed

The module file changes the relative path of a symlink to absolute #65448

robertdebock opened this issue Dec 3, 2019 · 3 comments · Fixed by #73700
Assignees
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.

Comments

@robertdebock
Copy link
Contributor

SUMMARY

The file module changes the path of a relative symlink to absolute path.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

file

ANSIBLE VERSION
ansible 2.9.1
  config file = /Users/robertguy/.ansible.cfg
  configured module search path = [u'/Users/robertguy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]
CONFIGURATION
# (empty)
OS / ENVIRONMENT

controller: mac
target: centos:8

STEPS TO REPRODUCE

Prepare a container:

# Start a container:
docker run -ti centos:8 /bin/bash
# Verify /sbin:
ls -ld /sbin
lrwxrwxrwx 1 root root 8 May 11  2019 /sbin -> usr/sbin

Run ansible on the container:

ansible -i $(docker ps -ql), -c docker all -m file -a "path=/sbin mode=o-w" -vvv
...
    "changed": true, 
    "dest": "/sbin", 
    "diff": {
        "after": {
            "path": "/sbin", 
            "src": "/usr/sbin"
        }, 
        "before": {
            "path": "/sbin", 
            "src": "usr/sbin"
        }
    }, 
...

# Verify /sbin again:
ls -ld /sbin
lrwxrwxrwx 1 root root    9 Dec  3 08:13 /sbin -> /usr/sbin
EXPECTED RESULTS

I was hoping that file would follow the symlink '/sbin' and change the target only. In the example above you can see that the link itself is modified.

ACTUAL RESULTS
ansible -i $(docker ps -ql), -c docker all -m file -a "path=/sbin mode=o-w follow=yes" -vvv
ansible 2.9.1
  config file = /Users/robertguy/.ansible.cfg
  configured module search path = [u'/Users/robertguy/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /Library/Python/2.7/site-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.10 (default, Feb 22 2019, 21:55:15) [GCC 4.2.1 Compatible Apple LLVM 10.0.1 (clang-1001.0.37.14)]
Using /Users/robertguy/.ansible.cfg as config file
Parsed de83dc6fa5ee, inventory source with host_list plugin
META: ran handlers
<de83dc6fa5ee> ESTABLISH DOCKER CONNECTION FOR USER: root
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u"/bin/sh -c 'echo ~ && sleep 0'"]
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u'/bin/sh -c \'( umask 77 && mkdir -p "` echo /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252 `" && echo ansible-tmp-1575362596.14-246033153918252="` echo /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252 `" ) && sleep 0\'']
<de83dc6fa5ee> Attempting python interpreter discovery
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u'/bin/sh -c \'echo PLATFORM; uname; echo FOUND; command -v \'"\'"\'/usr/bin/python\'"\'"\'; command -v \'"\'"\'python3.7\'"\'"\'; command -v \'"\'"\'python3.6\'"\'"\'; command -v \'"\'"\'python3.5\'"\'"\'; command -v \'"\'"\'python2.7\'"\'"\'; command -v \'"\'"\'python2.6\'"\'"\'; command -v \'"\'"\'/usr/libexec/platform-python\'"\'"\'; command -v \'"\'"\'/usr/bin/python3\'"\'"\'; command -v \'"\'"\'python\'"\'"\'; echo ENDFOUND && sleep 0\'']
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u"/bin/sh -c '/usr/libexec/platform-python && sleep 0'"]
Using module file /Library/Python/2.7/site-packages/ansible/modules/files/file.py
<de83dc6fa5ee> PUT /Users/robertguy/.ansible/tmp/ansible-local-18934l8TrvG/tmp_uA5WD TO /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252/AnsiballZ_file.py
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u"/bin/sh -c 'chmod u+x /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252/ /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252/AnsiballZ_file.py && sleep 0'"]
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u"/bin/sh -c '/usr/libexec/platform-python /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252/AnsiballZ_file.py && sleep 0'"]
<de83dc6fa5ee> EXEC ['/usr/local/bin/docker', 'exec', '-i', u'de83dc6fa5ee', u'/bin/sh', '-c', u"/bin/sh -c 'rm -f -r /root/.ansible/tmp/ansible-tmp-1575362596.14-246033153918252/ > /dev/null 2>&1 && sleep 0'"]
de83dc6fa5ee | CHANGED => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/libexec/platform-python"
    }, 
    "changed": true, 
    "dest": "/sbin", 
    "diff": {
        "after": {
            "path": "/sbin", 
            "src": "/usr/sbin"
        }, 
        "before": {
            "path": "/sbin", 
            "src": "usr/sbin"
        }
    }, 
    "gid": 0, 
    "group": "root", 
    "invocation": {
        "module_args": {
            "_diff_peek": null, 
            "_original_basename": null, 
            "access_time": null, 
            "access_time_format": "%Y%m%d%H%M.%S", 
            "attributes": null, 
            "backup": null, 
            "content": null, 
            "delimiter": null, 
            "directory_mode": null, 
            "follow": true, 
            "force": false, 
            "group": null, 
            "mode": "o-w", 
            "modification_time": null, 
            "modification_time_format": "%Y%m%d%H%M.%S", 
            "owner": null, 
            "path": "/sbin", 
            "recurse": false, 
            "regexp": null, 
            "remote_src": null, 
            "selevel": null, 
            "serole": null, 
            "setype": null, 
            "seuser": null, 
            "src": null, 
            "state": "link", 
            "unsafe_writes": null
        }
    }, 
    "mode": "0777", 
    "owner": "root", 
    "size": 9, 
    "src": "/usr/sbin", 
    "state": "link", 
    "uid": 0
}
META: ran handlers
META: ran handlers
@ansibot
Copy link
Contributor

ansibot commented Dec 3, 2019

Files identified in the description:

If these files are inaccurate, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Dec 3, 2019
@jillr jillr added needs_verified This issue needs to be verified/reproduced by maintainer P3 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Dec 12, 2019
@ansibot
Copy link
Contributor

ansibot commented May 16, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@eqrx eqrx self-assigned this Feb 22, 2021
@eqrx
Copy link
Contributor

eqrx commented Feb 23, 2021

Have verified this and produced an integration test that I will attach to the PR that is to come.

@eqrx eqrx removed the needs_verified This issue needs to be verified/reproduced by maintainer label Feb 23, 2021
@eqrx eqrx added the has_pr This issue has an associated PR. label Feb 23, 2021
eqrx added a commit that referenced this issue Mar 1, 2021
The file module changes existing sym links from relative to absolute
if the src is not stated in the tasks since it uses `os.path.realpath`
to fetch the link source and not `os.readlink`. Changed that.
@ansible ansible locked and limited conversation to collaborators Mar 29, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. files Files category has_pr This issue has an associated PR. module This issue/PR relates to a module. P3 Priority 3 - Approved, No Time Limitation python3 support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants