我使用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時它纔會失敗。
就像我說的錯誤不與任何Python庫相關的腳本工作完全正常不使用become_user。無論如何感謝 – paul
也許看看SELinux是什麼。這非常有道理,爲什麼你的任務運行時沒有'become_user'參數,而不是它,它在主機上運行一個sudo任務。 – udondan