使用 Ansible 将 tar 球从一台服务器复制到另一台服务器
Copying a tar ball from one server to another with Ansible
我正在尝试使用 Ansible
将 tar.gz
存档文件从控制主机复制到远程服务器。这是该剧的样子:
# 0. Copy tar ball into directory.
- name: copy java tar ball
tags: copyJavaTarBall
register: copyJavaTarBallOut
copy: src={{ javaSrcLocation }} dest={{ javaDestLocation }}
#shell: /bin/rsync -v -e "ssh -p {{ ansible_port }} -i {{ ansible_ssh_private_key_file }}" {{ javaSrcLocation }} sriram@{{ ansible_host }}:/home/sriram
#synchronize:
# src: {{ javaSrcLocation }}
# dest: {{ javaDestLocation }}
# rsync_opts:
#- "-e \" ssh -p {{ ansible_port }} -i {{ ansible_ssh_private_key_file }} \""
#delegate_to: localhost
- debug: var=copyJavaTarBallOut.stdout_lines
在所有这些文件中,copy
指令仅适用于简单文件(文本文件等)。使用 tar.gz
存档会导致以下错误:
task path: /root/ansible/playbooks/javaSetup.yml:22
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 119, in run
res = self._execute()
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 490, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/lib/python2.7/site-packages/ansible/plugins/action/copy.py", line 153, in run
source_full = self._loader.get_real_file(source_full)
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 402, in get_real_file
if is_encrypted_file(f):
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 152, in is_encrypted_file
b_vaulttext = to_bytes(to_text(vaulttext, encoding='ascii', errors='strict'), encoding='ascii', errors='strict')
File "/usr/lib/python2.7/site-packages/ansible/module_utils/_text.py", line 177, in to_text
return obj.decode(encoding, errors)
MemoryError
fatal: [xx.yy.zz.aa]: FAILED! => {
"failed": true,
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
将 rsync
与 synchronize
或 shell
指令一起使用会导致执行停滞。
我的问题:
1. 如何使用 Ansible 将 tar 球从控制主机复制到 target 服务器?
**更新:
- 像这样调用 Ansible:
ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook -vvvv -s javaSetup.yml --key-file=sshPvtKeys/pvtKeyFile.pem -c ssh --ask-sudo-pass -l appservers --tags copyJavaTarBall
- 文件大小为 147M。 RAM 大小大约为 1 GB。
使用Ansible
复制大文件时似乎存在内存问题。有一个relevant discussion here。
我采取的解决此问题的步骤:
1. 使用 split
将存档分成多个部分,如下所示:
split -b 10m jdk-7u79-linux-x64.tar.gz jdk-7u79-linux-x64.tar.gz.part-
2. 剧本是这样的:
# 0. Copy tar ball into directory.
- name: copy java tar ball
tags: copyJavaTarBall
register: copyJavaTarBallOut
copy: src={{ item }} dest={{ javaDestLocation }}
with_fileglob:
- "{{ javaSrcLocation }}/*"
- debug: var=copyJavaTarBallOut.stdout_lines
一旦移动到远程服务器,就需要将其合并(使用 cat
),然后取消存档。麻烦,但可以完成工作。
我正在尝试使用 Ansible
将 tar.gz
存档文件从控制主机复制到远程服务器。这是该剧的样子:
# 0. Copy tar ball into directory.
- name: copy java tar ball
tags: copyJavaTarBall
register: copyJavaTarBallOut
copy: src={{ javaSrcLocation }} dest={{ javaDestLocation }}
#shell: /bin/rsync -v -e "ssh -p {{ ansible_port }} -i {{ ansible_ssh_private_key_file }}" {{ javaSrcLocation }} sriram@{{ ansible_host }}:/home/sriram
#synchronize:
# src: {{ javaSrcLocation }}
# dest: {{ javaDestLocation }}
# rsync_opts:
#- "-e \" ssh -p {{ ansible_port }} -i {{ ansible_ssh_private_key_file }} \""
#delegate_to: localhost
- debug: var=copyJavaTarBallOut.stdout_lines
在所有这些文件中,copy
指令仅适用于简单文件(文本文件等)。使用 tar.gz
存档会导致以下错误:
task path: /root/ansible/playbooks/javaSetup.yml:22
An exception occurred during task execution. The full traceback is:
Traceback (most recent call last):
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 119, in run
res = self._execute()
File "/usr/lib/python2.7/site-packages/ansible/executor/task_executor.py", line 490, in _execute
result = self._handler.run(task_vars=variables)
File "/usr/lib/python2.7/site-packages/ansible/plugins/action/copy.py", line 153, in run
source_full = self._loader.get_real_file(source_full)
File "/usr/lib/python2.7/site-packages/ansible/parsing/dataloader.py", line 402, in get_real_file
if is_encrypted_file(f):
File "/usr/lib/python2.7/site-packages/ansible/parsing/vault/__init__.py", line 152, in is_encrypted_file
b_vaulttext = to_bytes(to_text(vaulttext, encoding='ascii', errors='strict'), encoding='ascii', errors='strict')
File "/usr/lib/python2.7/site-packages/ansible/module_utils/_text.py", line 177, in to_text
return obj.decode(encoding, errors)
MemoryError
fatal: [xx.yy.zz.aa]: FAILED! => {
"failed": true,
"msg": "Unexpected failure during module execution.",
"stdout": ""
}
将 rsync
与 synchronize
或 shell
指令一起使用会导致执行停滞。
我的问题:
1. 如何使用 Ansible 将 tar 球从控制主机复制到 target 服务器?
**更新:
- 像这样调用 Ansible:
ANSIBLE_KEEP_REMOTE_FILES=1 ansible-playbook -vvvv -s javaSetup.yml --key-file=sshPvtKeys/pvtKeyFile.pem -c ssh --ask-sudo-pass -l appservers --tags copyJavaTarBall
- 文件大小为 147M。 RAM 大小大约为 1 GB。
使用Ansible
复制大文件时似乎存在内存问题。有一个relevant discussion here。
我采取的解决此问题的步骤:
1. 使用 split
将存档分成多个部分,如下所示:
split -b 10m jdk-7u79-linux-x64.tar.gz jdk-7u79-linux-x64.tar.gz.part-
2. 剧本是这样的:
# 0. Copy tar ball into directory.
- name: copy java tar ball
tags: copyJavaTarBall
register: copyJavaTarBallOut
copy: src={{ item }} dest={{ javaDestLocation }}
with_fileglob:
- "{{ javaSrcLocation }}/*"
- debug: var=copyJavaTarBallOut.stdout_lines
一旦移动到远程服务器,就需要将其合并(使用 cat
),然后取消存档。麻烦,但可以完成工作。