2016-03-17 51 views
0

我使用become_user在连接到远程机器后更改用户 在此示例中,ssh user1将文件复制到远程计算机,然后我们通过user2更改用户,然后移动文件。 在这里,我有过程和最后的错误。使用become_user时出错复制资源

<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错误。但我相信是一个权限问题。

failed: [*********] => {"checksum": "f1f7d1e8f4fe6397dcc39fe4e2613b607e8c6fa1", "failed": true} 
    msg: Aborting, target uses selinux but python bindings (libselinux-python) aren't installed! 

所有的python库都安装正确,并且脚本工作正常,只有当我使用become_user时它才会失败。

回答

1

也许该包没有安装第二个用户。在python中使用virtualenv时,我遇到了这个问题。

作为解决方法,您可以做的是手动将/usr/lib64/python2.7/site-packages/selinux/的内容移动到Anisble尝试从中读取软件包的任何位置。使用-vvv选项时executiong你的剧本ansible-playbook file -vvv

当欲了解更多信息,可以看到这一点,你可以用这个Link

1

target uses selinux but python bindings (libselinux-python) aren't installed是一个非常明显的错误。检查是否安装了libselinux-python软件包。

Ansible documentation

如果您在远程节点上启用SELinux的,你也将要使用的任何拷贝/文件/模板相关的功能之前,在其上安装libselinux,蟒蛇Ansible。您当然可以使用Ansible中的yum模块将该软件包安装在没有它的远程系统上。

+0

就像我说的错误不与任何Python库相关的脚本工作完全正常不使用become_user。无论如何感谢 – paul

+0

也许看看SELinux是什么。这非常有道理,为什么你的任务运行时没有'become_user'参数,而不是它,它在主机上运行一个sudo任务。 – udondan