2016-12-01 82 views
1

我的Makefile有以下步驟運行即席wait_for與delegate_to

create: 
     do create stuff 
     # extra ansible adhoc command to wait for ssh 

    setup: 
     do other stuff 

我想do create stuff是等待,直到所有的主機有自己的SSH端口入店後添加了一步,但我不希望有犯一個額外的劇本,僅僅做到這一點:

- hosts: all 
    tasks: 
     - name: wait for ssh port 
     wait_for: 
      host: '{{ ansible_ssh_host }}' 
      port: 22 
      timeout: 300 
     delegate_to: localhost 

我使用即席命令將運行以上,但與當地的行動命令試圖

ansible all -i inventory -m local_action -a 'wait_for port=22 timeout=300' 

但那不是正確的原因

ERROR! this task 'local_action' has extra params, which is only allowed in the following modules: command, win_command, shell, win_shell, script, include, include_vars, add_host, group_by, set_fact, raw, meta 
+0

ansible本地主機-m wait_for -a「主機=本地主機端口= 22超時= 300」 – Shasha99

+0

你能解釋一下你想要達到的目標?這沒有多大意義。當您在劇本中執行它時,在爲其特定主機執行其他任務之前,多個任務將分別等待每個主機。當你在ad-hoc模式下執行它時,你只有一個線程,那麼如何針對多個目標運行它? – techraf

+0

我已經更新了這個問題,以使它更清楚我試圖做什麼 – user2599522

回答

1

我的Makefile有以下步驟

create: 
    do create stuff 
    # extra ansible adhoc command to wait for ssh 

從評論:

  • 所以,你要檢查是否所有目標服務器是否可以ping通? - Shasha99
  • 不能ping通。 SSH-能。

我不知道爲什麼你要聘請Ansible來做到這一點。這裏有一個簡單的bash循環(添加一個外循環訪問您的主機):

for i in {1..30}; do 
    ssh $host true 2> /dev/null 
    if [ $? -eq 0 ]; then 
    exit 
    else 
    sleep 10 
    fi 
done 
+0

我知道有辦法繞過它。林好奇,即時通訊建議是可能的(將adhoc,wait_for和delegate_to與任何組合) – user2599522