简体   繁体   English

配置接口vlan,如果其描述包含某个字与Ansible

[英]Configure interface vlan if its description contains a certain word with Ansible

I have been struggling for days to find a way to do this.我一直在努力寻找一种方法来做到这一点。

Currently I am able to gather the Cisco devices interfaces configuration in json with the ios_facts module, but now I cant figure how to use the data gathered to configure the interface vlan when its description contains a certain word.目前,我可以使用 ios_facts 模块在 json 中收集 Cisco 设备接口配置,但现在我不知道如何使用收集到的数据来配置接口 vlan,因为它的描述包含某个单词。

I would really appreciate a little hint我真的很感激一点提示

But now I cant figure how to use the data gathered to configure the interface vlan when its description contains a certain word.但是现在我不知道如何使用收集到的数据来配置接口 vlan,因为它的描述包含某个单词。

- name: get ios facts
  cisco.ios.ios_facts:
    gather_subset: all

- name: configure interface vlan when hostname contains something
  cisco.ios.ios_l2_interfaces:
    config:
    - name: GigabitEthernet0/1
      mode: access
      access:
        vlan: 10
      voice:
        vlan: 40
    - name: GigabitEthernet0/2
      mode: trunk
      trunk:
        allowed_vlans: 10-20,40
        native_vlan: 20
        pruning_vlans: 10,20
        encapsulation: dot1q
    state: merged
  when: "'abcdef' in ansible_net_hostname"

Take a look at the return values when using ios_facts .看看使用 ios_facts 时的返回值 It seems 'description' is not part of gathering the ios facts, so in my example I used the hostname.似乎“描述”不是收集 ios 事实的一部分,所以在我的示例中,我使用了主机名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM