Ansible 与代表一起运行临时等待

Ansible 与代表一起运行临时等待,ansible,Ansible,我的Makefile有以下步骤 create: do create stuff # extra ansible adhoc command to wait for ssh setup: do other stuff create: do create stuff # extra ansible adhoc command to wait for ssh 我想在do create stuff之后添加一个步骤,等待所有主机都可以

我的Makefile有以下步骤

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

   setup:
       do other stuff
create:
   do create stuff
   # extra ansible adhoc command to wait for ssh
我想在
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
我的Makefile有以下步骤

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

   setup:
       do other stuff
create:
   do create stuff
   # extra ansible adhoc command to wait for ssh
从评论中:

  • 因此,您要检查所有目标服务器是否都可ping?-
  • 不可ping。有能力的
我不知道你为什么要雇用Ansible来做这件事。下面是一个简单的bash循环(添加一个外部循环以在主机上迭代):

为我工作,以验证
wait_for
是否按我预期的方式工作:

ansible --inventory=PATH -m wait_for -a 'host=IP port=PORT delay=10 timeout=300' 127.0.0.1

ansible localhost-m wait_for-a'host=localhost port=22 timeout=300'您能解释一下您想要实现什么吗?这没有多大意义。在playbook中执行时,多个任务将分别等待每个主机,然后再继续执行其特定主机的其他任务。当你在特别模式下执行它时,你只有一个线程,那么你想如何针对多个目标运行它呢?我已经更新了这个问题,让我更清楚地了解我要做的事情:ansible all-m wait_for-a'host={ansible_ssh_host}port=22 timeout=30',但这将在服务器上执行命令,我需要检查它是否活动。它将失败,出现
SSH错误
我知道有办法解决它。我很好奇我的建议是否可行(临时组合、等待组合和授权组合)