Linux 是否将文件复制到远程服务器,但复制到属于其他用户的目录中?
我正在编写一个ansible playbook,它将我的Linux 是否将文件复制到远程服务器,但复制到属于其他用户的目录中?,linux,ansible,Linux,Ansible,我正在编写一个ansible playbook,它将我的tasks.tar.gz文件复制到远程服务器上,并将其解压缩到远程服务器上的特定目录中 我在machineA上以用户david的身份运行我的playbook,因此我从machineA向所有远程服务器authorized\u key文件添加了david用户的公钥,这样我就可以在不键入密码的情况下进行ssh,因为我想无密码运行我的ansible playbook --- - hosts: ALL serial: 3 tasks:
tasks.tar.gz
文件复制到远程服务器上,并将其解压缩到远程服务器上的特定目录中
我在machineA
上以用户david
的身份运行我的playbook,因此我从machineA
向所有远程服务器authorized\u key
文件添加了david
用户的公钥,这样我就可以在不键入密码的情况下进行ssh,因为我想无密码运行我的ansible playbook
---
- hosts: ALL
serial: 3
tasks:
- name: copy and untar latest tasks.tar.gz file
unarchive: src=tasks.tar.gz dest=/data/files/tasks/
- name: sleep for few seconds
pause: seconds=20
现在我遇到的问题是,远程服务器上的“/data/files/tasks/”目录属于其他用户(goldy)
,因此它无法复制和解压缩tasks.tar.gz
文件,因为我想我是以david
用户的身份运行我的playbook
ansible-playbook -e 'host_key_checking=False' test2.yml
我想以用户david
passwordless的身份运行我的ansible playbook,但它应该能够将文件复制到属于用户goldy的目录中的所有远程服务器中。我试着玩been
和been\u user
,但对我不起作用。还有什么我需要做的吗
- name: copy and untar latest tasks.tar.gz file
unarchive: src=tasks.tar.gz dest=/data/files/tasks/
become: true
become_user: goldy
become_method: sudo
这就是我得到的错误:
"msg": "Failed to set permissions on the temporary files Ansible needs to create when becoming an unprivileged user (rc: 1, err: chown: changing ownership of ‘/tmp/ansible-tmp-1518323151.21-195554555527544/’: Operation not permitted\nchown: changing ownership of ‘/tmp/ansible-tmp-1518323151.21-195554555527544/stat.py’: Operation not permitted\n}).
由于您提示为连接用户
david
配置sudo,因此最简单的方法是使用提升的权限复制文件,并通过unarchive
模块的owner
参数将其所有权设置为goldy
:
- name: copy and untar latest tasks.tar.gz file
unarchive:
src: tasks.tar.gz
dest: /data/files/tasks/
owner: goldy
become: true
对于如何配置sudoers以允许代表root用户以外的用户执行命令的问题,您需要了解
sudo
和sudoers
的实际工作方式(请参阅).配置sudoers。如果我通过putty登录所有删除服务器,那么david user可以将sudo添加到goldy user。如果这是您的意思?什么是“sudo添加到goldy user”?我的意思是“sudo su goldy”。当你说“配置sudoers”时,我仍然不明白我需要做什么?我甚至尝试了been\u方法:sudo
,但仍然失败了。我用错误消息更新了我的问题。我不知道我在这里做错了什么?