2016-09-22 68 views
4

我正在嘗試運行ansible-plabook,但它在安裝時掛起。我的劇本做了很多工作,比如調用不同的角色和模塊也收集事實。它用於精細早期的工作,但現在我不知道哪裏出了問題,任何幫助表示讚賞ansible-playbook在設置時掛起

  • 主機操作系統是RHEL 7
  • SSH密碼認證設置這些系統
  • 我的庫存文件之間只包含一個主機系統

命令我跑了

ansible-playbook -i /tmp/tmpBo5Xmj -vvvvv playbook.yml -c ssh 

這裏是詳細日誌

TASK [setup] ******************************************************************* 
<172.17.239.193> ESTABLISH SSH CONNECTION FOR USER: ansible 
<172.17.239.193> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no) 
<172.17.239.193> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.239.193> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.239.193> SSH: PlayContext set ssh_common_args:() 
<172.17.239.193> SSH: PlayContext set ssh_extra_args:() 
<172.17.239.193> SSH: EXEC ssh -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=10 172.17.239.193 '/bin/sh -c '"'"'(umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801 `" && echo ansible-tmp-1474582282.38-93511913696801="` echo $HOME/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801 `") && sleep 0'"'"'' 
<172.17.239.193> PUT /tmp/tmpAKnqv6 TO /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup 
<172.17.239.193> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no) 
<172.17.239.193> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.239.193> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.239.193> SSH: PlayContext set ssh_common_args:() 
<172.17.239.193> SSH: PlayContext set sftp_extra_args:() 
<172.17.239.193> SSH: EXEC sftp -b - -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=10 '[172.17.239.193]' 
<172.17.239.193> ESTABLISH SSH CONNECTION FOR USER: ansible 
<172.17.239.193> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.239.193> SSH: ansible_password/ansible_ssh_pass not set: (-o)(KbdInteractiveAuthentication=no)(-o)(PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey)(-o)(PasswordAuthentication=no) 
<172.17.239.193> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.239.193> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.239.193> SSH: PlayContext set ssh_common_args:() 
<172.17.239.193> SSH: PlayContext set ssh_extra_args:() 
<172.17.239.193> **SSH: EXEC ssh -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o StrictHostKeyChecking=no -o KbdInteractiveAuthentication=no -o PreferredAuthentications=gssapi-with-mic,gssapi-keyex,hostbased,publickey -o PasswordAuthentication=no -o User=ansible -o ConnectTimeout=10 -tt 172.17.239.193 '/bin/sh -c '"'"'sudo -H -S -n -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-njtihbebdvbpospbpivnpwbhrqtnfylc; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"''** 

在目標系統上,我可以看到以下運行

[[email protected] ~]# ps -ef | grep python| grep ansible 
ansible 12600 12568 0 07:18 pts/0 00:00:00 /bin/sh -c sudo -H -S -p "[sudo via ansible, key=tdtazugynuyekapktrkwjrwuawfvgkme] password: " -u root /bin/sh -c 'echo BECOME-SUCCESS-tdtazugynuyekapktrkwjrwuawfvgkme; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/" > /dev/null 2>&1' && sleep 0 
root  12613 12600 0 07:18 pts/0 00:00:00 sudo -H -S -p [sudo via ansible, key=tdtazugynuyekapktrkwjrwuawfvgkme] password: -u root /bin/sh -c echo BECOME-SUCCESS-tdtazugynuyekapktrkwjrwuawfvgkme; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/" > /dev/null 2>&1 
root  12614 12613 0 07:18 pts/0 00:00:00 /bin/sh -c echo BECOME-SUCCESS-tdtazugynuyekapktrkwjrwuawfvgkme; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/" > /dev/null 2>&1 
root  12615 12614 0 07:18 pts/0 00:00:00 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582204.64-194542154309618/setup 
root  12616 12615 0 07:18 pts/0 00:00:00 /usr/bin/python /tmp/ansible_0loivr/ansible_module_setup.py 
ansible 15436 15435 0 07:20 pts/1 00:00:00 /bin/sh -c sudo -H -S -n -u root /bin/sh -c 'echo BECOME-SUCCESS-njtihbebdvbpospbpivnpwbhrqtnfylc; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/" > /dev/null 2>&1' && sleep 0 
root  15449 15436 0 07:20 pts/1 00:00:00 sudo -H -S -n -u root /bin/sh -c echo BECOME-SUCCESS-njtihbebdvbpospbpivnpwbhrqtnfylc; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/" > /dev/null 2>&1 
root  15450 15449 0 07:20 pts/1 00:00:00 /bin/sh -c echo BECOME-SUCCESS-njtihbebdvbpospbpivnpwbhrqtnfylc; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/" > /dev/null 2>&1 
root  15451 15450 0 07:20 pts/1 00:00:00 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474582282.38-93511913696801/setup 
root  15452 15451 0 07:20 pts/1 00:00:00 /usr/bin/python /tmp/ansible_PJZfVt/ansible_module_setup.py 

下面是簡單的劇本,我在那裏設置成爲蟒蛇的過程:yes和become_user:根,不知何故當我設置成:是它不工作,它掛起

- name: list files in target system 
    hosts: clonedb 
    user: ansible 
    become: yes 
    become_user: root 
    gather_facts: yes 
    tasks: 
    - name: list files in target system 
    command: ls 
    always_run: true 
    tags: list 

如果我評論成爲和become_user它工作正常。我已經加入用戶ansible到目標系統sudoers文件列表中,但它仍然將它添加到sudoers文件列表

ansible   ALL=(ALL)  NOPASSWD: ALL 

我試着掛

我已經給須藤權限「ansible」用戶在目標系統上在目標系統上運行sudo命令爲ansible用戶正常工作

[[email protected] ~]$ sudo ls ~root 
anaconda-ks.cfg cvuqdisk-1.0.9-1.rpm install.log install.log.syslog remove_disk.sh 

但在其他系統上,它工作正常

(virtualapp) [[email protected] lib]$ python odcansible.py 
sys path:['/home/ansible/virtualapp/pypi_portal/lib', '/home/ansible/virtualapp/lib64/python27.zip', '/home/ansible/virtualapp/lib64/python2.7', '/home/ansible/virtualapp/lib64/python2.7/plat-linux2', '/home/ansible/virtualapp/lib64/python2.7/lib-tk', '/home/ansible/virtualapp/lib64/python2.7/lib-old', '/home/ansible/virtualapp/lib64/python2.7/lib-dynload', '/usr/lib64/python2.7', '/usr/lib/python2.7', '/home/ansible/virtualapp/lib/python2.7/site-packages'] 
PLAY [create temporary directory in target system] ***************************** 

TASK [setup] ******************************************************************* 
<172.17.58.95> ESTABLISH SSH CONNECTION FOR USER: ansible 
<172.17.58.95> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no)(-o)(IdentitiesOnly=yes)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s) 
<172.17.58.95> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.58.95> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.58.95> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.58.95> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r) 
<172.17.58.95> SSH: EXEC sshpass -d14 ssh -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=ansible -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r 172.17.58.95 '/bin/sh -c '"'"'(umask 77 && mkdir -p "` echo $HOME/.ansible/tmp/ansible-tmp-1474661320.71-273658467725557 `" && echo ansible-tmp-1474661320.71-273658467725557="` echo $HOME/.ansible/tmp/ansible-tmp-1474661320.71-273658467725557 `") && sleep 0'"'"'' 
<172.17.58.95> PUT /tmp/tmpITvUgQ TO /home/ansible/.ansible/tmp/ansible-tmp-1474661320.71-273658467725557/setup 
<172.17.58.95> SSH: disable batch mode for sshpass: (-o)(BatchMode=no) 
<172.17.58.95> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no)(-o)(IdentitiesOnly=yes)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s) 
<172.17.58.95> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.58.95> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.58.95> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.58.95> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r) 
<172.17.58.95> SSH: EXEC sshpass -d14 sftp -o BatchMode=no -b - -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=ansible -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r '[172.17.58.95]' 
<172.17.58.95> ESTABLISH SSH CONNECTION FOR USER: ansible 
<172.17.58.95> SSH: ansible.cfg set ssh_args: (-o)(UserKnownHostsFile=/dev/null)(-o)(StrictHostKeyChecking=no)(-o)(IdentitiesOnly=yes)(-o)(ControlMaster=auto)(-o)(ControlPersist=60s) 
<172.17.58.95> SSH: ANSIBLE_HOST_KEY_CHECKING/host_key_checking disabled: (-o)(StrictHostKeyChecking=no) 
<172.17.58.95> SSH: ANSIBLE_REMOTE_USER/remote_user/ansible_user/user/-u set: (-o)(User=ansible) 
<172.17.58.95> SSH: ANSIBLE_TIMEOUT/timeout set: (-o)(ConnectTimeout=10) 
<172.17.58.95> SSH: found only ControlPersist; added ControlPath: (-o)(ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r) 
<172.17.58.95> SSH: EXEC sshpass -d14 ssh -C -vvv -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -o IdentitiesOnly=yes -o ControlMaster=auto -o ControlPersist=60s -o StrictHostKeyChecking=no -o User=ansible -o ConnectTimeout=10 -o ControlPath=/home/ansible/.ansible/cp/ansible-ssh-%h-%p-%r -tt 172.17.58.95 '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=wcazqfwywctzrpesmznhbpbibluqmkqg] password: " -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-wcazqfwywctzrpesmznhbpbibluqmkqg; LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8 /usr/bin/python /home/ansible/.ansible/tmp/ansible-tmp-1474661320.71-273658467725557/setup; rm -rf "/home/ansible/.ansible/tmp/ansible-tmp-1474661320.71-273658467725557/" > /dev/null 2>&1'"'"'"'"'"'"'"'"' && sleep 0'"'"'' 
ok: [172.17.58.95] 
+0

看起來很奇怪'sudo'正在運行,因爲它仍然處於設置階段。但是這讓我覺得這個問題實際上是在你的sudoers配置中。 –

回答

0

你能否澄清你的問題?

你說你的目標是收集有關主持人的事實 - 但你的手冊沒有反映這一點。

如果您唯一的目標是收集有關主機的事實,則可以使用該任務的設置模塊。你也不需要一本劇本來收集關於主持人的事實。

ansible clonedb -m setup -u ansible 

使用用戶「ansible」驗證收集你「clonedb」主機組事實將上述臨時命令。如果您不使用SSH密鑰對服務器進行身份驗證,則需要傳遞「-k」選項以提示輸入SSH密碼。

但是,收集事實的最好方法是通過劇本。您可以進一步簡化您的劇本,只是做到以下幾點:

--- 
- hosts: clonedb 
    user: ansible 

    tasks: 
    - name: gather facts 
    action: setup 

你不需要特權帳戶來收集有關主機的事實。

「gather_facts」選項默認設置爲True。除非在ansible.cfg中明確將其設置爲「False」,否則沒有必要在Playbook中指定它。

您應該將您的事實存儲在redis或通過json文件中,因爲一旦劇本完成,事實將從內存中刪除。

http://docs.ansible.com/ansible/playbooks_variables.html#fact-caching

編輯:

你的劇本的簡化版本:

--- 
- hosts: clonedb 
    user: ansible 
    become: yes 

    tasks: 
    - name: list files 
    command: ls 
    always_run: true 

    register: listfiles 
    - debug: var=listfiles 
+0

感謝您的回覆,我不僅僅是收集事實。我只舉了一個例子(ls)。我有幾個角色,我在那個劇本中打了個電話。其中一些以root用戶,oracle用戶,網格用戶身份運行。所以我需要用戶成爲:是和成爲用戶:根,不知何故,這是行不通的。 –

+0

我建議簡化你的劇本。沒有必要使用become_user:root並且變成:yes。成爲:是的是一個特權升級。您的playbook運行在我的測試虛擬機上,因此遠程計算機上的sudoers文件可能存在問題。 – Avalon

+0

我更新了我的答案,其中包括將顯示文件列表的Playbook的簡化版本。 – Avalon

0

做一些調試和網絡搜索後,我發現這個問題 https://github.com/ansible/ansible/issues/12025

這是ansible 2.0 如果我設置成:在t之前的主要級別是問它掛起,但如果我把它裏面的任務它的工作原理

下面的劇本將無法正常工作

- hosts: clonedb 
    user: ansible 
    become: yes 

    tasks: 
    - name: list files 
    command: ls 
    always_run: true 

    register: listfiles 
    - debug: var=listfiles 

,但是這一個工程 - 主機:clonedb 用戶:ansible

tasks: 
    - name: list files 
    command: ls 
    always_run: true 
    become: yes 
    become_user: root 

    register: listfiles 
    - debug: var=listfiles 
0

嘗試檢查嘗試連接到目標計算機的用戶的主文件夾中的權限。我在我自己的目標機器上運行這個命令:/home/ansiblechmod 775 -R /home/ansible。你應該選擇你的用戶名。

0

我有同樣的問題,我登錄到遠程箱和刪除由ansible創建的目錄固定它:

(remote_box)$ rm -Rf ~/.ansible

這是由於這樣的事實,我打斷了之前的ansible會議。