在特定主机组的 Ansible 中检查 wait_for 不起作用 [英] Checking wait_for in Ansible in a particular host group does not work

查看:28
本文介绍了在特定主机组的 Ansible 中检查 wait_for 不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类似于

  ---
  - name: testplaybook
  hosts:
  gather_facts: yes
  roles:
     -role: samplerole

角色:

 - name: checking for port open
   wait-for: 
      timeout: 3
      host: groups['git_groups']
      port: 7809
      ignore_error: yes
      register: port_check

对于上面的代码,主机:groups['git_groups'] 在这里不能作为输入.当我运行剧本时,它会检查整个主机列表,而不是该特定组.

For the above code the host: groups['git_groups'] doesn't work as an input here. When I run the playbook, it checks for the entire lists of hosts rather than that particular group.

推荐答案

您不能将任意数据结构(在您的情况下为列表)提供给需要字符串(等待的可解析主机名或 IP 地址").

You cannot feed an arbitrary data structure (list in your case) to an argument of a module which requires a string ("A resolvable hostname or IP address to wait for").

您应该使用 with_items 循环:

You should use a with_items loop:

- name: checking for port open
  wait_for: 
    timeout: 3
    host: "{{ item }}"
    port: 7809
  ignore_error: yes
  register: port_check
  with_items: "{{ groups['git_groups'] }}"

您还有两个任务指令缩进错误.

这篇关于在特定主机组的 Ansible 中检查 wait_for 不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆