ansible rsync,在远程主机上使用 sudo 密码

问题描述 投票:0回答:1

我尝试与 ansible 一起使用同步,它使用 rsync。

我有这个任务:

   - name: Synchronization of src on the control machine to dest on the remote hosts become: yes ansible.posix.synchronize: src: ./ dest: "{{ var_app_path }}/"

我收到此错误:

fatal: [ip_adress]: FAILED! => {"changed": false, "cmd": "/usr/bin/rsync --delay-updates -F --compress --archive --rsh=/usr/bin/ssh -S none -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null --rsync-path=sudo rsync --out-format=<<CHANGED>>%i %n%L /builds/nickname/spa2023/ debian@ip_adress:/app/", "msg": "Warning: Permanently added 'ip_adress' (ECDSA) to the list of known hosts.\r\nsudo: a terminal is required to read the password; either use the -S option to read from standard input or configure an askpass helper\nsudo: a password is required\nrsync: connection unexpectedly closed (0 bytes received so far) [sender]\nrsync error: error in rsync protocol data stream (code 12) at io.c(228) [sender=3.2.3]\n", "rc": 12}

显然,该命令要求输入密码,但没有让终端给出 sudo 密码?

你如何解决这个问题?我现在使用复制,速度非常非常慢。

该命令在管道 ci/cid 中运行:

ansible-playbook -u $LOGIN -i "$SERVER_IP," --extra-vars “ansible_sudo_pass=$SUDO_PASSWORD” playbook.yml

谢谢你

我尝试使用ask-become手动运行

ansible synchronization
1个回答
0
投票

所以你可以尝试强制终端。

如在 SSH 手册页中所示:

-t 强制伪终端分配。这可以用来 在远程执行任意基于屏幕的程序 机器,这可能非常有用,例如实施时 菜单服务。多个 -t 选项强制 tty 分配, 即使 ssh 没有本地 tty。

在 Ansible SSH 连接上应用该方法的方法是在 ansible.builtin.ssh_connection 中管理的。 我们可以使用

ssh_args
选项。默认值为
ssh_args = -C -o ControlMaster=auto -o ControlPersist=60s
,所以我们只需添加
-t
。您可以首先使用命令对其进行测试。

ansible-playbook -u $LOGIN -i "$SERVER_IP," --extra-vars "ansible_sudo_pass=$SUDO_PASSWORD" "ansible_ssh_common_args=' -C -o ControlMaster=auto -o ControlPersist=60s -t'" playbook.yml

© www.soinside.com 2019 - 2024. All rights reserved.