1

所以我试图在 Juniper ex2300 上配置一个接口,但我只想配置第一个免费接口。我知道,当您注册值时,所有值都会被注册,这令人沮丧,因为我不需要跳过的值。

但我只想使用任务中满足条件的第一个接口,Print results但我一直想做的是:

- name: Configure Interface
  juniper_junos_command
    commands:
       set interface {{item}} unit 0 family inet address 192.168.1.1/24
  loop: "{{ready.results}}"
  when: 
    #item not skipped
    #end loop

Yaml 文件

  tasks:
    - name: Get interfaces
      juniper_junos_command:
        formats: xml
        commands:
          - show interfaces
      register: inter

    - name: Print results
      debug:
        msg: "{{item.name}}"
      loop: "{{ inter.parsed_output['interface-information']['physical-interface'] }}"
      loop_control:
        label: "{{ item.name }}"
      when:
        - item['oper-status'] == "down"
        - item['admin-status'] == "down"
        - item.name | regex_search('(^[xg]e.*)')
        - item.description == "** SPARE **"
      ignore_errors: yes
      register: ready

这里是ready输出的一部分
我不想使用的第一项和我想要使用的第二项。但是,它可能永远不会是一致的 ge-0/0/0 或 ge-0/0/1

"ready": {
        "changed": false,
        "msg": "All items completed",
        "results": [
            {
                "_ansible_ignore_errors": null,
                "_ansible_item_label": "ge-0/0/0",
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_verbose_always": true,
                "changed": false,
                "failed": false,
                "item": {
                    "active-alarms": {
                        "interface-alarms": {
                            "ethernet-alarm-link-down": ""
                        }
                    },
                    "active-defects": {
                        "interface-alarms": {
                            "ethernet-alarm-link-down": ""
                        }
                    },
                    "admin-status": "up",
                    "bpdu-error": "none",
                    "current-physical-address": "f0:4b:3a:72:48:63",
                    "description": "Link to CLIENTS",
                    "duplex": "Auto",
                    "hardware-physical-address": "f0:4b:3a:72:48:63",
                    "ieee-802-3az-eee": "disabled",
                    "if-auto-negotiation": "enabled",
                    "if-config-flags": {
                        "iff-hardware-down": "",
                        "iff-snmp-traps": "",
                        "internal-flags": "0x4000"
                    },
                    "if-device-flags": {
                        "ifdf-down": "",
                        "ifdf-present": "",
                        "ifdf-running": ""
                    },
                    "if-flow-control": "disabled",
                    "if-media-flags": {
                        "ifmf-none": ""
                    },
                    "if-media-type": "Copper",
                    "if-remote-fault": "online",
                    "interface-flapped": "2000-01-02 11:50:01 NZDT (02:48:34 ago)",
                    "interface-transmit-statistics": "Disabled",
                    "l2pt-error": "none",
                    "ld-pdu-error": "none",
                    "link-level-type": "Ethernet",
                    "link-mode": "Full-duplex",
                    "local-index": "648",
                    "logical-interface": {
                        "address-family": {
                            "address-family-flags": {
                                "ifff-is-primary": "",
                                "ifff-port-mode-trunk": "",
                                "internal-flags": "0x4400000"
                            },
                            "address-family-name": "eth-switch",
                            "mtu": "1514"
                        },
                        "encapsulation": "Ethernet-Bridge",
                        "filter-information": "",
                        "if-config-flags": {
                            "iff-device-down": "",
                            "iff-snmp-traps": "",
                            "internal-flags": "0x24024000"
                        },
                        "local-index": "561",
                        "logical-interface-bandwidth": "0",
                        "name": "ge-0/0/0.0",
                        "policer-overhead": "",
                        "snmp-index": "526",
                        "traffic-statistics": {
                            "input-packets": "1448",
                            "output-packets": "20"
                        }
                    },
                    "loopback": "disabled",
                    "mtu": "1514",
                    "name": "ge-0/0/0",
                    "oper-status": "down",
                    "physical-interface-cos-information": {
                        "physical-interface-cos-hw-max-queues": "8",
                        "physical-interface-cos-use-max-queues": "8"
                    },
                    "snmp-index": "513",
                    "sonet-mode": "LAN-PHY",
                    "source-filtering": "disabled",
                    "speed": "Auto",
                    "traffic-statistics": {
                        "input-bps": "0",
                        "input-pps": "0",
                        "output-bps": "0",
                        "output-pps": "0"
                    }
                },
                "msg": "ge-0/0/0"
            },{
                "_ansible_ignore_errors": null,
                "_ansible_item_label": "ge-0/0/1",
                "_ansible_item_result": true,
                "_ansible_no_log": false,
                "_ansible_verbose_always": true,
                "changed": false,
                "failed": false,
                "item": {
                    "active-alarms": {
                        "interface-alarms": {
                            "ethernet-alarm-link-down": ""
                        }
                    },
                    "active-defects": {
                        "interface-alarms": {
                            "ethernet-alarm-link-down": ""
                        }
                    },
                    "admin-status": "up",
                    "bpdu-error": "none",
                    "current-physical-address": "f0:4b:3a:72:48:64",
                    "description": "Link to CLIENTS",
                    "duplex": "Auto",
                    "hardware-physical-address": "f0:4b:3a:72:48:64",
                    "ieee-802-3az-eee": "disabled",
                    "if-auto-negotiation": "enabled",
                    "if-config-flags": {
                        "iff-hardware-down": "",
                        "iff-snmp-traps": "",
                        "internal-flags": "0x4000"
                    },
                    "if-device-flags": {
                        "ifdf-down": "",
                        "ifdf-present": "",
                        "ifdf-running": ""
                    },
                    "if-flow-control": "disabled",
                    "if-media-flags": {
                        "ifmf-none": ""
                    },
                    "if-media-type": "Copper",
                    "if-remote-fault": "online",
                    "interface-flapped": "2000-01-02 11:41:10 NZDT (02:57:26 ago)",
                    "interface-transmit-statistics": "Disabled",
                    "l2pt-error": "none",
                    "ld-pdu-error": "none",
                    "link-level-type": "Ethernet",
                    "link-mode": "Half-duplex",
                    "local-index": "649",
                    "logical-interface": {
                        "address-family": {
                            "address-family-flags": {
                                "ifff-port-mode-trunk": "",
                                "internal-flags": "0x4400000"
                            },
                            "address-family-name": "eth-switch",
                            "mtu": "1514"
                        },
                        "encapsulation": "Ethernet-Bridge",
                        "filter-information": "",
                        "if-config-flags": {
                            "iff-device-down": "",
                            "iff-snmp-traps": "",
                            "internal-flags": "0x24024000"
                        },
                        "local-index": "562",
                        "name": "ge-0/0/1.0",
                        "policer-overhead": "",
                        "snmp-index": "531",
                        "traffic-statistics": {
                            "input-packets": "0",
                            "output-packets": "0"
                        }
                    },
                    "loopback": "disabled",
                    "mtu": "1514",
                    "name": "ge-0/0/1",
                    "oper-status": "down",
                    "physical-interface-cos-information": {
                        "physical-interface-cos-hw-max-queues": "8",
                        "physical-interface-cos-use-max-queues": "8"
                    },
                    "snmp-index": "514",
                    "sonet-mode": "LAN-PHY",
                    "source-filtering": "disabled",
                    "speed": "Auto",
                    "traffic-statistics": {
                        "input-bps": "0",
                        "input-pps": "0",
                        "output-bps": "0",
                        "output-pps": "0"
                    }
                },
                "msg": "ge-0/0/1"
            }        
        ]
    }
}

如何使用我在命令中遇到的第一个项目然后停止循环?

4

0 回答 0