目前,我正在使用代码将某些目录中的二进制文件链接到/usr/local/bin
- name: Find the files to link in /usr/local/bin
find:
paths:
- "/usr/local/java/jdk1.8.0_171/bin/"
- "/usr/local/java/apache-maven-3.3.3/bin"
register: usrlocalbinfiles
- name: Link SDK files
file:
src: "{{item.path}}"
dest: "/usr/local/bin/{{item.path|basename}}"
state: link
with_items: "{{usrlocalbinfiles.files}}"
become: yes
如果我使用此代码和调试选项(-vvv)检查剧本的执行情况,我会看到ansible连接到远程主机,列表中的每个项目。我的~/.ansible.cfg
具有启用共享ssh连接的下一个选项
[defaults]
host_key_checking = False
become=True
become_method='su'
[ssh_connection]
ssh_args=-o ControlMaster=auto -o ControlPersist=120s -o ControlPath=/tmp/ansible-ssh-%h-%p-%r -o ForwardAgent=yes
是否可以加快使用此代码的剧本?问题是使用with_item
的循环:每个项目使用ssh的连接。
答案 0 :(得分:1)
另外添加
[ssh_connection]
pipelining = true
如果您看到多个ssh调用,则不使用流水线操作。如果有ssh
次呼叫:
SSH: EXEC ssh ... python && sleep 0
然后流水线正在运作。