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

时间:2015-11-25 17:37:15

标签: linux ansible rsync overwrite

在我的Ansible角色" xen"中,我有这个任务:

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

我想将以下结构复制到目的地,而不会覆盖现有文件夹中的文件,例如/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

该任务有效,但取代了/lib64 中的所有文件。那杀死了我的服务器:

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

这里是详细的任务输出,为简洁而截断:

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…"}

奇怪的是,该任务并没有删除/boot中的现有文件。

我确保明确指定delete=no,以防万一,因此&#34; Delete files that don't exist (after transfer, not before) in the src path.&#34;

为什么Ansible&#39;同步&#39;模块替换/lib64但是按预期复制到/boot

1 个答案:

答案 0 :(得分:0)

问题是 /lib64不是目录。这是一个象征性的链接:

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

让Ansible&#39;同步&#39; rsync您的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)

解决方法

复制到/usr/lib64。将库复制到/etc/ansible/xenhost/xen/files/install/usr/lib64而不是/etc/ansible/xenhost/xen/files/install/lib64,并确保后一个路径不存在。