简体   繁体   English

即使删除=否,Ansible的“同步”也会覆盖文件夹

[英]Ansible 'synchronize' overwrites folder even though delete=no

In my Ansible role "xen", I have this task: 在我的Ansible角色“ xen”中,我有以下任务:

---
- name: Install Xen
  synchronize: src=install/
               dest=/
               archive=yes
               delete=no

I want to copy the following structure to the destination without overwriting files in the existing folders like /boot and /lib64 : 我想将以下结构复制到目标位置,而不覆盖/boot/lib64等现有文件夹中的文件:

root@node51 [~]# tree -L 1 /etc/ansible/xenhost/xen/files/install
/etc/ansible/xenhost/xen/files/install
├── boot
├── etc
├── lib64
├── usr
└── var

5 directories, 0 files

The task worked, but it replaced all the files in /lib64 . 该任务有效,但替换了/lib64所有文件 That killed my server: 那杀死了我的服务器:

[root@localhost ~]# ls /lib64/
-bash: /usr/bin/ls: /lib64/ld-linux-x86-64.so.2: bad ELF interpreter: No such file or directory

Here's the verbose task output, truncated for brevity: 这是冗长的任务输出,为简洁起见被截断了:

TASK: [xen | Install Xen] ***************************************************** 
<127.0.0.1> EXEC ['/bin/sh', '-c', 'mkdir -p $HOME/.ansible/tmp/ansible-tmp-1448470134.66-193795609318676 && echo $HOME/.ansible/tmp/ansible-tmp-1448470134.66-193795609318676']
<127.0.0.1> PUT /tmp/tmpb7EusD TO /root/.ansible/tmp/ansible-tmp-1448470134.66-193795609318676/synchronize
<127.0.0.1> EXEC ['/bin/sh', '-c', u'LANG=C LC_CTYPE=C /usr/bin/python /root/.ansible/tmp/ansible-tmp-1448470134.66-193795609318676/synchronize; rm -rf /root/.ansible/tmp/ansible-tmp-1448470134.66-193795609318676/ >/dev/null 2>&1']
changed: [192.168.0.123] => {"changed": true, "cmd": "rsync --delay-updates -FF --compress --archive --rsh 'ssh  -o StrictHostKeyChecking=no' --out-format='<<CHANGED>>%i %n%L' \"/etc/ansible/xenhost/xen/files/install/\" \"root@192.168.0.123:/\"", "msg": "…truncated…"}

Curiously, the task didn't erase the existing files in /boot . 奇怪的是,该任务并未清除/boot的现有文件。

I made sure to specify delete=no explicitly, just in case, so it should not " Delete files that don't exist (after transfer, not before) in the src path. " 我确信指定delete=no明确,为了以防万一,所以它应该“ 删除不存在的(转移之后,而不是之前)文件src路径。

Why did the Ansible 'synchronize' module replace /lib64 but copy to /boot as expected? 为什么Ansible的“同步”模块替换了/lib64却按预期复制到了/boot

The issue is that /lib64 is not a directory . 问题是/lib64不是目录 It is a symbolic link: 这是一个符号链接:

[root@localhost ~]# file /lib64
/lib64: symbolic link to `usr/lib64'

By having Ansible 'synchronize' rsync your lib64 directory, it removes the symbolic link and puts an actual folder in its place . 通过具有Ansible“同步” rsynclib64目录,它消除了符号链接,并把实际的文件夹中自己的位置

As a result, the libraries in /usr/lib64 are no longer reachable from /lib64 , which is why everything that depended on finding libraries in /lib64 failed: 结果, /usr/lib64不再可以访问/usr/lib64中的/lib64 ,这就是所有依赖于/lib64查找库的原因都失败了的原因:

[root@localhost ~]# ldd /usr/bin/ls
    linux-vdso.so.1 =>  (0x00007fffa9118000)
    libselinux.so.1 => /lib64/libselinux.so.1 (0x00007fe4b9630000)
    libcap.so.2 => /lib64/libcap.so.2 (0x00007fe4b9428000)
    libacl.so.1 => /lib64/libacl.so.1 (0x00007fe4b9218000)
    libc.so.6 => /lib64/libc.so.6 (0x00007fe4b8e50000)
    libpcre.so.1 => /lib64/libpcre.so.1 (0x00007fe4b8be8000)
    liblzma.so.5 => /lib64/liblzma.so.5 (0x00007fe4b89c0000)
    libdl.so.2 => /lib64/libdl.so.2 (0x00007fe4b87b8000)
    /lib64/ld-linux-x86-64.so.2 (0x00007fe4b9860000)
    libattr.so.1 => /lib64/libattr.so.1 (0x00007fe4b85b0000)
    libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fe4b8390000)

Remedy 补救

Copy to /usr/lib64 instead. 复制到/usr/lib64 Put the libraries to copy in /etc/ansible/xenhost/xen/files/install/usr/lib64 instead of in /etc/ansible/xenhost/xen/files/install/lib64 , and make sure the latter path does not exist. 将要复制的库放在/etc/ansible/xenhost/xen/files/install/usr/lib64而不是在/etc/ansible/xenhost/xen/files/install/lib64 ,并确保后一个路径不存在。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Ansible Playbook 中删除服务器所有目录中的特定文件夹/文件 - Delete specific folder/files in all the directories of the server from the Ansible Playbook Ansible 重新启动不重新启动,即使“/var/run/reboot-required”存在 - Ansible reboot not rebooting even though '/var/run/reboot-required' exists Ansible中的同步模块,用于在远程主机上复制文件 - synchronize module in Ansible for copying files on remote hosts 即使文件夹存在,挂载点也不存在。 可以手动挂载 - Mount point does not exist, even though folder exists. Able to mount manually AOSP:arm-linux-androideabi-gcc:即使在prebuilts文件夹中也没有找到命令 - AOSP: arm-linux-androideabi-gcc: command not found even though it is present in prebuilts folder 为什么即使apache是​​该组的成员,也不能写入文件夹? - Why can't apache write to a folder even though it's a member of the group? 如何将CDN文件夹同步到本地文件夹? - How to synchronize a CDN folder to a local folder? 如何使用 Ansible 删除 cron 作业? - How to delete a cron job with Ansible? 使用 lftp 将本地文件夹与 ftp 文件夹同步的语法? - Syntax for using lftp to synchronize local folder with an ftp folder? 即使符号存在,dlsym也会返回NULL - dlsym returns NULL, even though the symbol exists
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM