#directory #ansible #synchronization #file-transfer
#каталог #ansible #синхронизация #передача файлов
Вопрос:
Я хочу скопировать файлы и папки с {{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/<file or folder>
локального хоста на удаленный хост назначения, но он также копирует все содержимое в {{ playbook_dir }}
каталоге.
В приведенной ниже книге host
воспроизведения упоминается как remote host
Ниже приведен мой ansible playbook, который отлично работает, когда src
это файл или набор файлов.
- name: "Copying files from local ansible host tmpfiles to target Destination server `{{ inventory_hostname }}`when the destination path is specified"
synchronize:
src: "{{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/{{ item | basename }}"
dest: "/tmp/moht/"
mode: push
rsync_opts: ""
with_items:
- "{{ source_file.split() }}"
Проблема возникает, когда внутри есть папка {{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/
.
Проблема в том, что любой каталог, скажем shif
, т.е. {{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/shif
Другие файлы из playbook_dir
каталога также копируются в папку назначения /tmp/mohtas
Вот как ansible НЕПРАВИЛЬНО сконструировал команду rsync, как видно из отладки.
TASK [Copying files from local ansible host tmpfiles to target Destination server `desthost`when the destination path is specified] ***
task path: /web/playbooks/filecopy/copyfiles.yml:215
changed: [desthost] => (item=/tmp/shif) => {"changed": true, "cmd": "/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/share/centrifydc/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --out-format=<<CHANGED>>%i %n%L /web/playbooks/filecopy/tmpfiles/93/shif destuser@desthost:/tmp/mohtas/", "item": "/tmp/shif", "msg": ".d..t...... ./n<f adddesttohost.ymln<f allmwhosts.hostsn<f backupfiles.ymln<f copyfiles.retryn<f copyfiles.ymln<f dircheck.ymln<f dircheckinner.ymlncd shif/n<f shif/72.logncd shif/log/n<f shif/log/1.logn<f shif/log/2.logncd shif/log/12/ncd shif/log/13/n<f shif/log/13/2.logncd tmpfiles/n<f tmpfiles/copyfilesvelocity.ymln<f tmpfiles/reqvelocityinstall.ymln<f tmpfiles/velocityserver.hostsncd tmpfiles/13/ncd tmpfiles/14/n<f tmpfiles/14/allmwhosts.hostsncd tmpfiles/16/n<f tmpfiles/16/allmwhosts.hostsncd tmpfiles/19/n<f tmpfiles/19/ssl.confncd tmpfiles/22/ncd tmpfiles/23/ncd tmpfiles/24/n<f tmpfiles/24/ssl.confncd tmpfiles/25/n<f tmpfiles/25/ssl.confncd tmpfiles/26/n<f tmpfiles/26/ssl.confncd tmpfiles/27/n<f tmpfiles/27/ssl.confncd tmpfiles/28/n<f tmpfiles/28/ssl.confncd tmpfiles/29/n<f tmpfiles/29/ssl.confncd tmpfiles/30/n<f tmpfiles/30/ssl.confncd tmpfiles/31/n<f tmpfiles/31/ssl.confncd tmpfiles/32/n<f tmpfiles/32/ssl.confncd tmpfiles/35/ncd tmpfiles/36/ncd tmpfiles/37/n<f tmpfiles/37/sixhundredperm.txtncd tmpfiles/38/ncd tmpfiles/39/ncd tmpfiles/40/ncd tmpfiles/41/ncd tmpfiles/42/n<f tmpfiles/42/sixhundredperm.txtncd tmpfiles/43/n<f tmpfiles/43/sixhundredperm.txtncd tmpfiles/44/n<f tmpfiles/44/sixhundredperm.txtncd tmpfiles/45/n<f tmpfiles/45/sixhundredperm.txtncd tmpfiles/46/n<f tmpfiles/46/sixhundredperm.txtncd tmpfiles/47/n<f tmpfiles/47/sixhundredperm.txtncd tmpfiles/48/n<f tmpfiles/48/sixhundredperm.txtncd tmpfiles/49/n<f tmpfiles/49/sixhundredperm.txtncd tmpfiles/50/n<f tmpfiles/50/sixhundredperm.txtncd tmpfiles/51/n<f tmpfiles/51/sixhundredperm.txtncd tmpfiles/52/n<f tmpfiles/52/sixhundredperm.txtncd tmpfiles/53/n<f tmpfiles/53/sixhundredperm.txtncd tmpfiles/54/n<f tmpfiles/54/sixhundredperm.txtncd tmpfiles/55/n<f tmpfiles/55/sixhundredperm.txtncd tmpfiles/56/n<f tmpfiles/56/sixhundredperm.txtncd tmpfiles/58/n<f tmpfiles/58/sixhundredperm.txtncd tmpfiles/61/n<f tmpfiles/61/sixhundredperm.txtncd tmpfiles/62/n<f tmpfiles/62/sixhundredperm.txtncd tmpfiles/63/n<f tmpfiles/63/sixhundredperm.txtncd tmpfiles/64/n<f tmpfiles/64/sixhundredperm.txtncd tmpfiles/66/n<f tmpfiles/66/sixhundredperm.txtn<f tmpfiles/66/test.txtncd tmpfiles/67/n<f tmpfiles/67/sixhundredperm.txtn<f tmpfiles/67/test.txtncd tmpfiles/68/n<f tmpfiles/68/sixhundredperm.txtn<f tmpfiles/68/test.txtncd tmpfiles/69/n<f tmpfiles/69/sixhundredperm.txtn<f tmpfiles/69/test.txtncd tmpfiles/70/n<f tmpfiles/70/sixhundredperm.txtn<f tmpfiles/70/test.txtncd tmpfiles/71/n<f tmpfiles/71/sixhundredperm.txtn<f tmpfiles/71/test.txtncd tmpfiles/73/n<f tmpfiles/73/sixhundredperm.txtn<f tmpfiles/73/test.txtncd tmpfiles/74/n<f tmpfiles/74/sixhundredperm.txtn<f tmpfiles/74/test.txtncd tmpfiles/75/n<f tmpfiles/75/sixhundredperm.txtn<f tmpfiles/75/test.txtncd tmpfiles/76/n<f tmpfiles/76/sixhundredperm.txtn<f tmpfiles/76/test.txtncd tmpfiles/77/n<f tmpfiles/77/sixhundredperm.txtn<f tmpfiles/77/test.txtncd tmpfiles/78/n<f tmpfiles/78/sixhundredperm.txtn<f tmpfiles/78/test.txtncd tmpfiles/79/n<f tmpfiles/79/sixhundredperm.txtn<f tmpfiles/79/test.txtncd tmpfiles/80/n<f tmpfiles/80/sixhundredperm.txtn<f tmpfiles/80/test.txtncd tmpfiles/81/n<f tmpfiles/81/sixhundredperm.txtn<f tmpfiles/81/test.txtncd tmpfiles/82/n<f tmpfiles/82/sixhundredperm.txtn<f tmpfiles/82/test.txtncd tmpfiles/83/n<f tmpfiles/83/sixhundredperm.txtn<f tmpfiles/83/test.txtncd tmpfiles/84/ncd tmpfiles/84/shif/n<f tmpfiles/84/shif/72.logncd tmpfiles/84/shif/log/n<f tmpfiles/84/shif/log/1.logn<f tmpfiles/84/shif/log/2.logncd tmpfiles/84/shif/log/12/ncd tmpfiles/84/shif/log/13/n<f tmpfiles/84/shif/log/13/2.logncd tmpfiles/85/n<f tmpfiles/85/72.logncd tmpfiles/85/log/n<f tmpfiles/85/log/1.logn<f tmpfiles/85/log/2.logncd tmpfiles/85/log/12/ncd tmpfiles/85/log/13/n<f tmpfiles/85/log/13/2.logncd tmpfiles/86/ncd tmpfiles/86/shif/n<f tmpfiles/86/shif/72.logncd tmpfiles/86/shif/log/n<f tmpfiles/86/shif/log/1.logn<f tmpfiles/86/shif/log/2.logncd tmpfiles/86/shif/log/12/ncd tmpfiles/86/shif/log/13/n<f tmpfiles/86/shif/log/13/2.logncd tmpfiles/87/n<f tmpfiles/87/sixhundredperm.txtncd tmpfiles/88/n<f tmpfiles/88/sixhundredperm.txtn<f tmpfiles/88/test.txtncd tmpfiles/89/ncd tmpfiles/89/shif/n<f tmpfiles/89/shif/72.logncd tmpfiles/89/shif/log/n<f tmpfiles/89/shif/log/1.logn<f tmpfiles/89/shif/log/2.logncd tmpfiles/89/shif/log/12/ncd tmpfiles/89/shif/log/13/n<f tmpfiles/89/shif/log/13/2.logncd tmpfiles/90/ncd tmpfiles/90/shif/n<f tmpfiles/90/shif/72.logncd tmpfiles/90/shif/log/n<f tmpfiles/90/shif/log/1.logn<f tmpfiles/90/shif/log/2.logncd tmpfiles/90/shif/log/12/ncd tmpfiles/90/shif/log/13/n<f tmpfiles/90/shif/log/13/2.logncd tmpfiles/91/ncd tmpfiles/91/shif/n<f tmpfiles/91/shif/72.logncd tmpfiles/91/shif/log/n<f tmpfiles/91/shif/log/1.logn<f tmpfiles/91/shif/log/2.logncd tmpfiles/91/shif/log/12/ncd tmpfiles/91/shif/log/13/n<f tmpfiles/91/shif/log/13/2.logncd tmpfiles/92/ncd tmpfiles/92/shif/n<f tmpfiles/92/shif/72.logncd tmpfiles/92/shif/log/n<f tmpfiles/92/shif/log/1.logn<f tmpfiles/92/shif/log/2.logncd tmpfiles/92/shif/log/12/ncd tmpfiles/92/shif/log/13/n<f tmpfiles/92/shif/log/13/2.logncd tmpfiles/93/ncd tmpfiles/93/shif/n<f tmpfiles/93/shif/72.logncd tmpfiles/93/shif/log/n<f tmpfiles/93/shif/log/1.logn<f tmpfiles/93/shif/log/2.logncd tmpfiles/93/shif/log/12/ncd tmpfiles/93/shif/log/13/n<f tmpfiles/93/shif/log/13/2.logn", "rc": 0, "stdout_lines": [".d..t...... ./", "<f adddesttohost.yml", "<f allmwhosts.hosts", "<f backupfiles.yml", "<f copyfiles.retry", "<f copyfiles.yml", "<f dircheck.yml", "<f dircheckinner.yml", "cd shif/", "<f shif/72.log", "cd shif/log/", "<f shif/log/1.log", "<f shif/log/2.log", "cd shif/log/12/", "cd shif/log/13/", "<f shif/log/13/2.log", "cd tmpfiles/", "<f tmpfiles/copyfilesvelocity.yml", "<f tmpfiles/reqvelocityinstall.yml", "<f tmpfiles/velocityserver.hosts", "cd tmpfiles/13/", "cd tmpfiles/14/", "<f tmpfiles/14/allmwhosts.hosts", "cd tmpfiles/16/", "<f tmpfiles/16/allmwhosts.hosts", "cd tmpfiles/19/", "<f tmpfiles/19/ssl.conf", "cd tmpfiles/22/", "cd tmpfiles/23/", "cd tmpfiles/24/", "<f tmpfiles/24/ssl.conf", "cd tmpfiles/25/", "<f tmpfiles/25/ssl.conf", "cd tmpfiles/26/", "<f tmpfiles/26/ssl.conf", "cd tmpfiles/27/", "<f tmpfiles/27/ssl.conf", "cd tmpfiles/28/", "<f tmpfiles/28/ssl.conf", "cd tmpfiles/29/", "<f tmpfiles/29/ssl.conf", "cd tmpfiles/30/", "<f tmpfiles/30/ssl.conf", "cd tmpfiles/31/", "<f tmpfiles/31/ssl.conf", "cd tmpfiles/32/", "<f tmpfiles/32/ssl.conf", "cd tmpfiles/35/", "cd tmpfiles/36/", "cd tmpfiles/37/", "<f tmpfiles/37/sixhundredperm.txt", "cd tmpfiles/38/", "cd tmpfiles/39/", "cd tmpfiles/40/", "cd tmpfiles/41/", "cd tmpfiles/42/", "<f tmpfiles/42/sixhundredperm.txt", "cd tmpfiles/43/", "<f tmpfiles/43/sixhundredperm.txt", "cd tmpfiles/44/", "<f tmpfiles/44/sixhundredperm.txt", "cd tmpfiles/45/", "<f tmpfiles/45/sixhundredperm.txt", "cd tmpfiles/46/", "<f tmpfiles/46/sixhundredperm.txt", "cd tmpfiles/47/", "<f tmpfiles/47/sixhundredperm.txt", "cd tmpfiles/48/", "<f tmpfiles/48/sixhundredperm.txt", "cd tmpfiles/49/", "<f tmpfiles/49/sixhundredperm.txt", "cd tmpfiles/50/", "<f tmpfiles/50/sixhundredperm.txt", "cd tmpfiles/51/", "<f tmpfiles/51/sixhundredperm.txt", "cd tmpfiles/52/", "<f tmpfiles/52/sixhundredperm.txt", "cd tmpfiles/53/", "<f tmpfiles/53/sixhundredperm.txt", "cd tmpfiles/54/", "<f tmpfiles/54/sixhundredperm.txt", "cd tmpfiles/55/", "<f tmpfiles/55/sixhundredperm.txt", "cd tmpfiles/56/", "<f tmpfiles/56/sixhundredperm.txt", "cd tmpfiles/58/", "<f tmpfiles/58/sixhundredperm.txt", "cd tmpfiles/61/", "<f tmpfiles/61/sixhundredperm.txt", "cd tmpfiles/62/", "<f tmpfiles/62/sixhundredperm.txt", "cd tmpfiles/63/", "<f tmpfiles/63/sixhundredperm.txt", "cd tmpfiles/64/", "<f tmpfiles/64/sixhundredperm.txt", "cd tmpfiles/66/", "<f tmpfiles/66/sixhundredperm.txt", "<f tmpfiles/66/test.txt", "cd tmpfiles/67/", "<f tmpfiles/67/sixhundredperm.txt", "<f tmpfiles/67/test.txt", "cd tmpfiles/68/", "<f tmpfiles/68/sixhundredperm.txt", "<f tmpfiles/68/test.txt", "cd tmpfiles/69/", "<f tmpfiles/69/sixhundredperm.txt", "<f tmpfiles/69/test.txt", "cd tmpfiles/70/", "<f tmpfiles/70/sixhundredperm.txt", "<f tmpfiles/70/test.txt", "cd tmpfiles/71/", "<f tmpfiles/71/sixhundredperm.txt", "<f tmpfiles/71/test.txt", "cd tmpfiles/73/", "<f tmpfiles/73/sixhundredperm.txt", "<f tmpfiles/73/test.txt", "cd tmpfiles/74/", "<f tmpfiles/74/sixhundredperm.txt", "<f tmpfiles/74/test.txt", "cd tmpfiles/75/", "<f tmpfiles/75/sixhundredperm.txt", "<f tmpfiles/75/test.txt", "cd tmpfiles/76/", "<f tmpfiles/76/sixhundredperm.txt", "<f tmpfiles/76/test.txt", "cd tmpfiles/77/", "<f tmpfiles/77/sixhundredperm.txt", "<f tmpfiles/77/test.txt", "cd tmpfiles/78/", "<f tmpfiles/78/sixhundredperm.txt", "<f tmpfiles/78/test.txt", "cd tmpfiles/79/", "<f tmpfiles/79/sixhundredperm.txt", "<f tmpfiles/79/test.txt", "cd tmpfiles/80/", "<f tmpfiles/80/sixhundredperm.txt", "<f tmpfiles/80/test.txt", "cd tmpfiles/81/", "<f tmpfiles/81/sixhundredperm.txt", "<f tmpfiles/81/test.txt", "cd tmpfiles/82/", "<f tmpfiles/82/sixhundredperm.txt", "<f tmpfiles/82/test.txt", "cd tmpfiles/83/", "<f tmpfiles/83/sixhundredperm.txt", "<f tmpfiles/83/test.txt", "cd tmpfiles/84/", "cd tmpfiles/84/shif/", "<f tmpfiles/84/shif/72.log", "cd tmpfiles/84/shif/log/", "<f tmpfiles/84/shif/log/1.log", "<f tmpfiles/84/shif/log/2.log", "cd tmpfiles/84/shif/log/12/", "cd tmpfiles/84/shif/log/13/", "<f tmpfiles/84/shif/log/13/2.log", "cd tmpfiles/85/", "<f tmpfiles/85/72.log", "cd tmpfiles/85/log/", "<f tmpfiles/85/log/1.log", "<f tmpfiles/85/log/2.log", "cd tmpfiles/85/log/12/", "cd tmpfiles/85/log/13/", "<f tmpfiles/85/log/13/2.log", "cd tmpfiles/86/", "cd tmpfiles/86/shif/", "<f tmpfiles/86/shif/72.log", "cd tmpfiles/86/shif/log/", "<f tmpfiles/86/shif/log/1.log", "<f tmpfiles/86/shif/log/2.log", "cd tmpfiles/86/shif/log/12/", "cd tmpfiles/86/shif/log/13/", "<f tmpfiles/86/shif/log/13/2.log", "cd tmpfiles/87/", "<f tmpfiles/87/sixhundredperm.txt", "cd tmpfiles/88/", "<f tmpfiles/88/sixhundredperm.txt", "<f tmpfiles/88/test.txt", "cd tmpfiles/89/", "cd tmpfiles/89/shif/", "<f tmpfiles/89/shif/72.log", "cd tmpfiles/89/shif/log/", "<f tmpfiles/89/shif/log/1.log", "<f tmpfiles/89/shif/log/2.log", "cd tmpfiles/89/shif/log/12/", "cd tmpfiles/89/shif/log/13/", "<f tmpfiles/89/shif/log/13/2.log", "cd tmpfiles/90/", "cd tmpfiles/90/shif/", "<f tmpfiles/90/shif/72.log", "cd tmpfiles/90/shif/log/", "<f tmpfiles/90/shif/log/1.log", "<f tmpfiles/90/shif/log/2.log", "cd tmpfiles/90/shif/log/12/", "cd tmpfiles/90/shif/log/13/", "<f tmpfiles/90/shif/log/13/2.log", "cd tmpfiles/91/", "cd tmpfiles/91/shif/", "<f tmpfiles/91/shif/72.log", "cd tmpfiles/91/shif/log/", "<f tmpfiles/91/shif/log/1.log", "<f tmpfiles/91/shif/log/2.log", "cd tmpfiles/91/shif/log/12/", "cd tmpfiles/91/shif/log/13/", "<f tmpfiles/91/shif/log/13/2.log", "cd tmpfiles/92/", "cd tmpfiles/92/shif/", "<f tmpfiles/92/shif/72.log", "cd tmpfiles/92/shif/log/", "<f tmpfiles/92/shif/log/1.log", "<f tmpfiles/92/shif/log/2.log", "cd tmpfiles/92/shif/log/12/", "cd tmpfiles/92/shif/log/13/", "<f tmpfiles/92/shif/log/13/2.log", "cd tmpfiles/93/", "cd tmpfiles/93/shif/", "<f tmpfiles/93/shif/72.log", "cd tmpfiles/93/shif/log/", "<f tmpfiles/93/shif/log/1.log", "<f tmpfiles/93/shif/log/2.log", "cd tmpfiles/93/shif/log/12/", "cd tmpfiles/93/shif/log/13/", "<f tmpfiles/93/shif/log/13/2.log"]}
Как я могу убедиться, что файл или папка присутствуют {{ playbook_dir }}/tmpfiles/{{ Latest_Build_Number }}/
только в этом файле / папке или комбинация файлов и папок копируется в папку назначения /tmp/mohtas
?
Ответ №1:
Проблема с копированием дополнительных файлов возникла из-за rsync_opts: ""
Я установил default(omit)
, было ли rsync_opts
оно пустым во время выполнения.
Обучение: никогда не сохраняйте rsync_opts: ""
лучше опускать.