Reputation: 1916
There are following two ways to run a script on the target machine:
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
As i am running the playbook against more than 30 target machines. I would like to know which one will be a better choice ?
Also what is the performance penalty if i prefer one over other ?
Upvotes: 1
Views: 602
Reputation: 337
If you are executing the script from the ansible machine, the ansible server will copy the script to temp location in the remote machine to execute.
So, the better choice is "run the script from the control machine directly" because of below reasons
Upvotes: 2
Reputation: 1179
If the script has to do something on the remote machine, would be better if you copy it and execute directly on the remote. I don't think you would see any noticeable performance decrease in any of the two cases.
The only thing is that in case 1. you will have to ssh to the remote and execute the commands you need, thing that ansible already does for you.
Upvotes: 0