2016-03-17 72 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