Ansible 使用“成为用户”复制资源时出错

Ansible 使用“成为用户”复制资源时出错,ansible,Ansible,一旦连接到远程机器,我将使用Been_user更改用户 在本例中,ssh user1将文件复制到远程计算机中,然后逐个user2更改用户并移动文件。 这里是我的过程和最后的错误 <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gs

一旦连接到远程机器,我将使用Been_user更改用户 在本例中,ssh user1将文件复制到远程计算机中,然后逐个user2更改用户并移动文件。 这里是我的过程和最后的错误

   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o 
   ConnectTimeout=10 172.28.178.227 /bin/sh -c 'rc=flag; [ -r /tmp/profile-java ] || rc=2; [ -f /tmp/profile-java ] || rc=1; [ -d /tmp/profile-java ] && rc=3; python -V 2>/dev/null || rc=4; [ x"$rc" != "xflag" ] && echo "${rc} "/tmp/profile-java && exit 0; (python -c '"'"'import hashlib; BLOCKSIZE = 65536; hasher = hashlib.sha1(); afile = open("'"'"'/tmp/profile-java'"'"'", "rb") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'"'"' 2>/dev/null) || (python -c '"'"'import sha; BLOCKSIZE = 65536; hasher = sha.sha(); afile = open("'"'"'/tmp/profile-java'"'"'", "rb") buf = afile.read(BLOCKSIZE) while len(buf) > 0: hasher.update(buf) buf = afile.read(BLOCKSIZE) afile.close() print(hasher.hexdigest())'"'"' 2>/dev/null) || (echo '"'"'0 '"'"'/tmp/profile-java)'


   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.28.178.227 /bin/sh -c 'mkdir -p /tmp/ansible-tmp-1458229962.35-167690832134774 && chmod a+rx /tmp/ansible-tmp-1458229962.35-167690832134774 && echo /tmp/ansible-tmp-1458229962.35-167690832134774'


 <172.28.178.227> PUT /u01/app/jenkins/workspace/02_Customer-Order-Services/deploy-to-PPE/roles/jvm/files/profile-java.j2 TO /tmp/ansible-tmp-1458229962.35-167690832134774/source

   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.28.178.227 /bin/sh -c 'chmod a+r /tmp/ansible-tmp-1458229962.35-167690832134774/source'

   <172.28.178.227> PUT /tmp/tmpO9iYgq TO /tmp/ansible-tmp-1458229962.35-167690832134774/copy

   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.28.178.227 /bin/sh -c 'chmod a+r /tmp/ansible-tmp-1458229962.35-167690832134774/copy'

   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.28.178.227 /bin/sh -c 'su svc-cos -c "/bin/sh -c '"'"'echo BECOME-SUCCESS-kifkfsbasxqszcorqwgpmcigwmalvwnq; LANG=en_US.UTF-8 LC_CTYPE=en_US.UTF-8 python /tmp/ansible-tmp-1458229962.35-167690832134774/copy'"'"'"'

   <172.28.178.227> EXEC ssh -C -tt -vvv -o ControlMaster=auto -o Port=22 -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o ConnectTimeout=10 172.28.178.227 /bin/sh -c 'rm -rf /tmp/ansible-tmp-1458229962.35-167690832134774/ >/dev/null 2>&1'

所有python库都已正确安装,脚本工作正常,只是在使用Been_user时失败。

目标使用selinux,但未安装python绑定(libselinux-python)
是一个非常明显的错误。检查是否安装了
libselinux-python
软件包

从:

如果在远程节点上启用了SELinux,那么在Ansible中使用任何与复制/文件/模板相关的函数之前,还需要在远程节点上安装libselinux python。当然,您仍然可以使用Ansible中的yum模块在没有该软件包的远程系统上安装该软件包


可能没有为第二个用户安装软件包。我在python中使用virtualenv时遇到了这个问题

作为一种解决方法,您可以手动将:
/usr/lib64/python2.7/site packages/selinux/
的内容移动到Anisble试图从中读取包的任何位置。在执行playbook
ansible playbook文件-vvv


要了解更多信息,您可以使用这个

,就像我说的,这个错误与任何python库都没有关系,脚本在不使用Beenèu user的情况下工作得非常好。谢谢,也许你可以看看SELinux是什么。为什么您的任务在运行时没有
been\u user
参数,而不是在主机上运行sudo任务,这是非常有道理的。
  failed: [*********] => {"checksum": "f1f7d1e8f4fe6397dcc39fe4e2613b607e8c6fa1", "failed": true}
  msg: Aborting, target uses selinux but python bindings (libselinux-python) aren't installed!