【问题标题】:Ansible Playbook: I want to use ip address range in "hosts"Ansible Playbook:我想在“主机”中使用 IP 地址范围
【发布时间】:2022-06-28 02:40:42
【问题描述】:

Ansible Playbook:我想在“主机”中使用 IP 地址范围

我想执行从 10.134.10.1 到 10.134.10.99 IP 范围的剧本。即 10.134.10.[1-99].

我尝试了以下方法,但没有成功。

- name: Adhoc Commands
  hosts: "10.134.10.1-99"
  connection: local
  gather_facts: false

  tasks:
     - name: running multiple commands
       ios_command:
        commands: "{{ item }}"
       with_items: "{{ commandList }}"
       register: output

【问题讨论】:

  • 这能回答你的问题吗? Hosts with IP range
  • 尝试用 "10.134.10.[1:99]" 修改 "10.134.10.1-99"

标签: ansible ansible-inventory


【解决方案1】:

不要将ranges to declare different hosts in your inventorypatterns you use to target hosts 混淆,后者最终可以使用可以定义(某种)范围的正则表达式。

以下示例演示了这两个概念。

首先让我们定义一个广告资源(例如假货),其中我们将包含 2 个完整的网络,包括您在示例中定位的网络

all:
  vars:
    ansible_connection: local
  hosts:
    10.134.1[0:1].[1:254]:

然后是一个剧本,我们将只针对您想要到达的范围内的主机。

---
- hosts: ~^10\.134\.10\.[0-9]$, ~^10\.134\.10\.[0-9][0-9]$
  gather_facts: false

  tasks:
    - debug:
        msg: "I'm running on {{ inventory_hostname }}"

【讨论】:

    猜你喜欢
    • 2016-09-27
    • 1970-01-01
    • 1970-01-01
    • 2021-01-18
    • 1970-01-01
    • 2017-01-02
    • 1970-01-01
    • 1970-01-01
    • 2022-07-22
    相关资源
    最近更新 更多