salt icon indicating copy to clipboard operation
salt copied to clipboard

[BUG] 3001.x and 3002.x file.recurse: "keep_symlinks: True" not working correctly

Open m-bastian opened this issue 10 years ago • 29 comments

We have the following issue with 2015.8.1 and 2015.8.3 when using file.recurse with keep_symlinks set to True:

A softlink which name is a subset (Like: ^NAME_SOFTLINK* ) of other filenames in the same directory will let salt ignore these files by the next update. If "clean: True" is set too, these files would be also deleted from the slave. We discovered this while syncing some custom compiled linux libraries with the typical libxyz.so.X.0.0 -> libxyz.so.X -> libxyz.so linking.

A simple example:

   mkdir test; cd test
   touch test1 test2 test3
   ln -s test3 test

  cat << EOF > test.sls
   /tmp/test/:
   file.recurse:
     - source: salt://test/
     - include_empty: True
     - clean: True
     - keep_symlinks: True
  EOF

The output:

----------
          ID: /tmp/test/
    Function: file.recurse
      Result: True
     Comment: Recursively updated /tmp/test/
     Started: 12:00:59.395207
    Duration: 321.6 ms
     Changes:   
              ----------
              /tmp/test/test:
                  ----------
                  new:
                      /tmp/test/test

As you see only the symlink survives. All other matching files are ignored.

m-bastian avatar Dec 09 '15 11:12 m-bastian

@m-bastian, thanks for reporting. @lorengordon, do you have any ideas on this one?

jfindlay avatar Dec 09 '15 20:12 jfindlay

Sorry @jfindlay, haven't touched the file.recurse code, only file.replace...so all new to me.

Did this work in earlier versions?

Looking at the code in the head of 2015.8, the problem could be that the way the files are named in this example are matching the .startswith() test, resulting in the path getting removed from the list of filenames...?

lorengordon avatar Dec 09 '15 21:12 lorengordon

@m-bastian, can you run your test with debug logging and let us know if the output contains a string like '** skipping file ** {0}, it intersects a symlink'? That should tell us whether the files are matching that test I mentioned and getting removed from the list of files to copy down to the minion...

lorengordon avatar Dec 09 '15 21:12 lorengordon

@lorengordon, sorry for pinging you, then, but thanks for looking.

jfindlay avatar Dec 09 '15 23:12 jfindlay

@lorengordon, yes it does:

2015-12-10 08:35:31,689 [salt.loaded.int.states.file][DEBUG   ][24980] ** skipping file ** test/test, it intersects a symlink
2015-12-10 08:35:31,689 [salt.loaded.int.states.file][DEBUG   ][24980] ** skipping file ** test/test1, it intersects a symlink
2015-12-10 08:35:31,689 [salt.loaded.int.states.file][DEBUG   ][24980] ** skipping file ** test/test2, it intersects a symlink
2015-12-10 08:35:31,689 [salt.loaded.int.states.file][DEBUG   ][24980] ** skipping file ** test/test3, it intersects a symlink
2015-12-10 08:35:31,691 [salt.utils.lazy  ][DEBUG   ][24980] LazyLoaded user.info
2015-12-10 08:35:31,708 [salt.state       ][INFO    ][24980] {u'/tmp/test/test': {'new': u'/tmp/test/test'}}

I am a bit puzzled why salt throws a "skipping file" log entry for the symlink itself.

m-bastian avatar Dec 10 '15 07:12 m-bastian

I'm not sure what the reasoning is behind the startswith() logic, but I do think that is why this isn't working for you.

I looked back through the history for the file state module and found that logic was introduced here, but there isn't an explanation for the approach. I'm guessing it might be something to do with symlinked directories...? The previous approach used something like if symlinks.get(filename) in place of this test, but I think with the refactoring that would be equivalent to if lname == filename...

lorengordon avatar Dec 10 '15 18:12 lorengordon

@lorengordon: Thank you for your analysis. This seems to be the last in a series of patches that introduced the keep_symlinks functionality and is explained in issue https://github.com/saltstack/salt/issues/5645

m-bastian avatar Dec 11 '15 07:12 m-bastian

Any update on this?

m-bastian avatar Dec 16 '15 09:12 m-bastian

@m-bastian, not that I know of. No one has been assigned to this issue.

jfindlay avatar Dec 17 '15 18:12 jfindlay

Sorry to nag but ... any update or at least an estimate on this?

m-bastian avatar Feb 03 '16 13:02 m-bastian

@m-bastian, unfortunately, not yet. I think we may be able to add this to the list of bugs to work on for the next sprint though.

jfindlay avatar Feb 03 '16 23:02 jfindlay

Sorry but still not fixed?

ghost avatar Apr 13 '16 06:04 ghost

@killer2tester, not that I know of. We are trying to work through our bug backlog.

jfindlay avatar Apr 13 '16 21:04 jfindlay

Any chance this issue is going to be addressed in the near future?

tastycheesewhiz avatar Jun 28 '16 22:06 tastycheesewhiz

Same issue on salt 2017.7.2!

rogeriomm avatar Oct 25 '17 19:10 rogeriomm

Still broken in 2018.3 ...

m-bastian avatar Jul 27 '18 10:07 m-bastian

Still broken in 2019.2. Looking at the source, it appears that PR # 24930 may have broken this feature. I think @jacksontj may have been expecting that each source should have a hash, not realizing that there would be no hash for symlinks. Would it make sense and be the simplest on line 5521 to set name_sum to -1 to differentiate a symlink from a missing file?

jdshewey avatar Apr 30 '19 18:04 jdshewey

I am also having issues deploying/copying symlinks using file.recurse and keep_symlinks: True.

/etc/nginx:
  file.recurse:
    - source: salt://{{slspath}}/files/nginx
    - user: root
    - group: root
    - file_mode: 644
    - sym_mode: 777
    - dir_mode: 755
    - clean: True
    - include_empty: True
    - keep_symlinks: True
    - force_symlinks: True

but it ends up with: 2019-12-22 at 18 37

dynek avatar Dec 22 '19 17:12 dynek

@dynek - this looks to be a separate issue. Make sure that the path `./nodes/ocean-10/files/nginx/modules exists on your salt master at whatever the file root is. This is set in /etc/salt/master or /etc/salt/master.d/f_defaults.conf

file_roots:
  base:

If this is not set, I believe the default path would be /srv/salt/nodes/ocean-10/files/nginx/modules

If you are expecting salt to use another path or environment, you need to set saltenv on you salt minion and set a file root for that environment on the master in file_roots

jdshewey avatar Dec 23 '19 22:12 jdshewey

@jdshewey other files from this directory are copied without any problem. modules is actually a symlink (modules -> /usr/lib/nginx/modules) that I want to copy as-is . /usr/lib/nginx/modules doesn't exist on the master.

dynek avatar Dec 24 '19 22:12 dynek