Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ansible “我需要”;[警告]:无法匹配提供的主机模式,忽略;失败_Ansible - Fatal编程技术网

Ansible “我需要”;[警告]:无法匹配提供的主机模式,忽略;失败

Ansible “我需要”;[警告]:无法匹配提供的主机模式,忽略;失败,ansible,Ansible,我传递变量“host”,以便仅在环境的一个主机上执行某些工作: - name: Perform an action on a host hosts: "{{ host }}" roles: - role: mule_action 当主机在其生成的资源清册中不时[警告]:无法匹配提供的主机模式,忽略:MuleQ01 我需要这个失败,所以它在jenkins(我的Ansible编曲)中显示为失败的构建 我的ansible.cfg如下所示: [defaults] strategy_plug

我传递变量“host”,以便仅在环境的一个主机上执行某些工作:

- name: Perform an action on a host
  hosts: "{{ host }}"
  roles:
  - role: mule_action
当主机在其生成的资源清册中时[警告]:无法匹配提供的主机模式,忽略:MuleQ01

我需要这个失败,所以它在jenkins(我的Ansible编曲)中显示为失败的构建

我的ansible.cfg如下所示:

[defaults]
strategy_plugins = /usr/lib/python3.6/site-packages/ansible_mitogen/plugins/strategy
strategy = mitogen_linear
host_key_checking = False
roles_path = roles
unparsed_is_failed = True
host_pattern_mismatch = error
inventory = inventory
运行: 表2.9.7 配置文件=/data/ansible.cfg 配置的模块搜索路径=['/home/mule/.ansible/plugins/modules',/usr/share/ansible/plugins/modules'] ansible python模块位置=/usr/lib/python3.6/site-packages/ansible 可执行文件位置=/usr/bin/ansible
python版本=3.6.9(默认值,2019年10月17日11:10:22)[GCC 8.3.0]

只需在检查之前进行检查,如果您的主机不在清单中,则失败

- fail:
    msg: "{{ host }} not in inventory group"
  when: host not in hostvars

除了前面的解决方案(检查清单中是否定义了单个主机)之外,我还发现此解决方案可用于检查清单中是否定义了一组主机,否则执行失败:

- hosts: localhost
  become: false
  tasks:
  - fail:
      msg: "Group my_own_group not defined in inventory"
    when: "'my_own_group' not in groups.keys()"