哪一个更好 ?直接从中控机执行脚本还是复制到本地执行?
Which one is better ? Executing script directly from control machine or copy and execute locally?
在目标机器上运行脚本有以下两种方式:
1. - name: run the script from the control machine directly.
script: "{{path_to_scripts}}/script.sh"
2. - name: Copying the script from target machine.
copy: src="{{path_to_scripts}}/script.sh" dest="{{path_to_scripts}}/script.sh" mode=0777
- name: Execute script locally.
command: /bin/sh {{path_to_scripts}}/script.sh
因为我正在 运行针对 30 多台目标机器编写剧本。我想知道哪个是更好的选择?
另外,如果我更喜欢一个而不是另一个,性能损失是多少?
如果脚本必须在远程机器上执行某些操作,最好将其复制并直接在远程机器上执行。我认为在这两种情况下,您都不会看到任何明显的性能下降。
唯一的问题是,在情况 1 中,您必须通过 ssh 连接到远程并执行您需要的命令,而 ansible 已经为您完成了这些操作。
如果你从ansible机器上执行脚本,ansible服务器会将脚本复制到远程机器的临时位置来执行。
因此,更好的选择是 "run the script from the control machine directly",原因如下
- 你不需要通过 ssh 连接到所有 30 台机器来复制脚本
- 你可以用一行代码来完成需要 2
步骤(复制并执行)
- 没有性能差异,因为两种方法的作用相同
操作
在目标机器上运行脚本有以下两种方式:
1. - name: run the script from the control machine directly.
script: "{{path_to_scripts}}/script.sh"
2. - name: Copying the script from target machine.
copy: src="{{path_to_scripts}}/script.sh" dest="{{path_to_scripts}}/script.sh" mode=0777
- name: Execute script locally.
command: /bin/sh {{path_to_scripts}}/script.sh
因为我正在 运行针对 30 多台目标机器编写剧本。我想知道哪个是更好的选择?
另外,如果我更喜欢一个而不是另一个,性能损失是多少?
如果脚本必须在远程机器上执行某些操作,最好将其复制并直接在远程机器上执行。我认为在这两种情况下,您都不会看到任何明显的性能下降。
唯一的问题是,在情况 1 中,您必须通过 ssh 连接到远程并执行您需要的命令,而 ansible 已经为您完成了这些操作。
如果你从ansible机器上执行脚本,ansible服务器会将脚本复制到远程机器的临时位置来执行。
因此,更好的选择是 "run the script from the control machine directly",原因如下
- 你不需要通过 ssh 连接到所有 30 台机器来复制脚本
- 你可以用一行代码来完成需要 2 步骤(复制并执行)
- 没有性能差异,因为两种方法的作用相同 操作