微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Ansible 通过 ssh 同步

如何解决Ansible 通过 ssh 同步

我正在尝试自动备份到云 (Strato HiDrive)。我将云存储配置为只能通过 rsync 访问(通过 ssh 加密)。

手动执行此操作时,效果很好。

localuser$ rsync -rltDvzu --delete -e ssh . remoteuser@rsync.cloud.com:/users/remoteuser/

我试图将其转换为剧本:

- name: Synchronization of src on the control machine to dest on the remote hosts
  synchronize:
    src: /raid5/Pictures/
    dest: rsync://remoteuser@rsync.cloud.com:/users/remoteuser/
    recursive: yes
    private_key: /etc/ansible/roles/backup_server/files/id_rsa
    set_remote_user: no
    copy_links: no
    times: yes
    checksum: yes
    rsync_opts: -e "ssh"
  • 我尝试打开和关闭 set_remote_user。它要求我输入远程用户的密码。
  • 我尝试通过 set_fact 将 ansible_user 设置为 localuser 或 remoteuser。为远程用户显示密码提示

我尝试像这样使用 rsync_opts,因为我认为 private_key 被忽略了:

 -e "ssh -i /etc/ansible/roles/backup_server/files/id_rsa"

错误信息是:

"msg": "rsync: Failed to exec ssh -i /etc/ansible/roles/backup_server/files/id_rsa: No such file or directory"

感谢您的帮助。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。