Ansible 可以在不使用 add_hosts 模块的情况下匹配作为参数传递的主机吗

Can Ansible match hosts passed as parameter without using add_hosts module

是否可以将 IP 地址作为参数 'Source_IP' 传递给 ansible playbook 并将其用作主机?

下面是我的剧本ipinhost.yml:

---
- name: Play 2- Configure Source nodes
  hosts: "{{ Source_IP }}"
  serial: 1
  tasks:
   - name: Copying from "{{ inventory_hostname }}" to this ansible server.
     debug: 
       msg: "MY IP IS: {{ Source_IP }}" 

剧本无法 运行 并显示以下消息 "Could not match supplied host pattern." 输出:

  ansible-playbook ipinhost.yml -e Source_IP='10.8.8.11'
 [WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all'

 [WARNING]: Could not match supplied host pattern, ignoring: 10.8.8.11


PLAY [Play 2- Configure Source nodes] ***********************************************************************************************************************
skipping: no hosts matched

PLAY RECAP **************************************************************************************************************************************************

我不想使用 ansible 的 add_host 即我不想构建动态主机列表,因为 Source_IP 将始终是单个服务器。

请告诉我这是否可行以及如何调整我的剧本以使其 运行 主机匹配“10.8.8.11”?

如果总是单台主机,一个可能的解决方案是将一个静态内联清单传递给ansible-playbook。

  1. 将您的游戏定位到 'all' 组。 => hosts: all
  2. 使用一个主机的内联清单调用您的剧本。注意:命令中IP末尾的逗号很重要:
ansible-playbook -i 10.8.8.11, ipinhost.yml