我已尝试过,但没有效果。
我尝试过的命令:
sudo -u ec2-user ssh -i {{ sso_key_path }}@{{ sso_ip_address }} "sh sso_file.sh"
答案1
首先将文件传输到远程主机并在那里执行
- hosts: hosts_group
remote_user: ec2-user
become: yes
tasks:
- name: transfer the script
copy:
src: sso_file.sh
dest: /tmp
mode: 0777
- name: execute the script
command: sh /tmp/sso_file.sh