2017-06-29 107 views
0

做任務,我的主機之前初始化主機,它需要時間(約20秒)來初始化CLI會話,......做CLIAnsible等待在劇本

CLI init

我試圖做之前通過劇本ansible命令:

--- 
- name: Run show sub command 
    hosts: em 
    gather_facts: no 
    remote_user: duypn 



    tasks: 
    - name: wait for SSH to respond on all hosts 
    local_action: wait_for host=em port=22 delay=60 state=started 

    - name: run show sub command 
    raw: show sub id=xxxxx;display=term-type 

10分鐘後,ansible給我輸出這是不顯示子命令的結果:(

... 
["CLI Session initializing..", "Autocompleter initializing..", "CLI>This session has been IDLE for too long.", 
... 

我很高興聽到您的建議。謝謝:)

回答

0

我沒有針對你的複製粘貼解決方案,但我學到的一件事就是在ssh之後進行睡眠'up'以允許機器完成它的工作。這可能會讓你朝正確的方向發展。

- name: Wait for SSH to come up 
    local_action: wait_for 
       host={{ item.public_ip }} 
       port=22 
       state=started 
    with_items: "{{ ec2.instances }}" 

- name: waiting for a few seconds to let the machine start 
    pause: 
    seconds: 20 
+0

Tks for your solution。我試過,但結果相同。我只是想知道每個劇本都做了ssh連接還是每個任務都做了ssh連接? –

+0

這取決於你如何配置它。默認情況下,除非在ansible.cfg中用ssh_args = -o ControlMaster = no'指定,否則將重用ssh-connection。這將每次啓動一個新的SSH連接(並使Ansible慢得多)。 – Evert

+0

我很高興聽到你的回答。那麼在每個劇本中只做一個ssh連接的特定配置是什麼? –