【问题标题】:Ansible pattern matching doesn't work as expectedansible 模式匹配没有按预期工作
【发布时间】:2022-11-15 14:17:03
【问题描述】:

我无法找到为什么这个简单的模式似乎与任何东西都不匹配。我有两个ansible主机作为目标。这是我的库存文件:

[web_Xubuntu]
192.168.160.128

[database_Fedora]
192.168.160.132

这就是我的 YAML 剧本的样子:

  # Hosts: where our play will run and options it will run with
  hosts: *Fedora
  become: True
    #gather_facts: False

  # Vars: variables that will apply to the play, on all target systems
  vars:
    motd: "Welcome to Fedora Linux - Ansible Rocks\n"

  # Tasks: the list of tasks that will be executed within the playbook
  tasks:
    - name: Configure a MOTD (message of the day)
      copy:
        content: "{{ motd }}"
        dest: /etc/motd
      notify: MOTD changed

  # Handlers: the list of handlers that are executed as a notify key from a task
  handlers:
    - name: MOTD changed
      debug:
        msg: The MOTD was changed

在处理此剧本时,ansible 报告以下错误:

ERROR! We were unable to read either as JSON nor YAML, these are the errors we got from each:
JSON: Expecting value: line 1 column 1 (char 0)

Syntax Error while loading YAML.
  found undefined alias

The offending line appears to be:

  # Hosts: where our play will run and options it will run with
  hosts: *Fedora
         ^ here

您能否建议使用通配符的正确方法是什么?

【问题讨论】:

    标签: ansible yaml


    【解决方案1】:

    您只能将星号 *(通配符)与 FQDN 或 IP 一起使用。例如

    192.0.*
    *.example.com
    *.com
    

    Patterns: targeting hosts and groups

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-30
      • 1970-01-01
      • 2018-03-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-14
      • 1970-01-01
      相关资源
      最近更新 更多