Anonymous
Как извлечь факты с помощью dot в имени переменной ('interface.vlan_id')?
Сообщение
Anonymous » 03 апр 2025, 07:07
У меня есть этот образец Playbook, и он работает нормально.
Код: Выделить всё
- hosts: localhost
gather_facts: true
tasks:
- name: Print network interface details
debug:
msg: "{{ ansible_ens2f0.ipv4.network }}/{{ ansible_ens2f0.ipv4.netmask }}"
< /code>
Если я попробую с тегом VLAN (11)
Код: Выделить всё
- hosts: localhost
gather_facts: true
tasks:
- name: Print network interface details
debug:
msg: "{{ ansible_ens2f0.11.ipv4.network }}/{{ ansible_ens2f0.11.ipv4.netmask }}"
< /code>
Затем получение ошибки, короткими < /p>
dict object has no element 11
< /code>
и полное сообщение < /pbr /> TASK [Print network interface details] ***************************************************************************************************************************************************************************************************************************************
fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: dict object has no element 11\n\nThe error appears to have been in '/home/ubuntu/net.yml': line 4, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Print network interface details\n ^ here\n"}
Как мне объединить vlan_id в переменной?
Код: Выделить всё
ansible localhost -m setup
< /code>
"ansible_ens2f0.11": {
"active": true,
"device": "ens2f0.11",
"features": {
"esp_hw_offload": "off [fixed]",
"esp_tx_csum_hw_offload": "off [fixed]",
"fcoe_mtu": "off [requested on]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
"highdma": "on",
"hw_tc_offload": "off [fixed]",
"l2_fwd_offload": "off [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "off [fixed]",
"netns_local": "off [fixed]",
"ntuple_filters": "off [fixed]",
"receive_hashing": "off [fixed]",
"rx_all": "off [fixed]",
"rx_checksumming": "off [fixed]",
"rx_fcs": "off [fixed]",
"rx_gro_hw": "off [fixed]",
"rx_udp_tunnel_port_offload": "off [fixed]",
"rx_vlan_filter": "off [fixed]",
"rx_vlan_offload": "off [fixed]",
"rx_vlan_stag_filter": "off [fixed]",
"rx_vlan_stag_hw_parse": "off [fixed]",
"scatter_gather": "on",
"tcp_segmentation_offload": "on",
"tls_hw_record": "off [fixed]",
"tls_hw_rx_offload": "off [fixed]",
"tls_hw_tx_offload": "off [fixed]",
"tx_checksum_fcoe_crc": "off [requested on]",
"tx_checksum_ip_generic": "on",
"tx_checksum_ipv4": "off [fixed]",
"tx_checksum_ipv6": "off [fixed]",
"tx_checksum_sctp": "off [requested on]",
"tx_checksumming": "on",
"tx_esp_segmentation": "off [fixed]",
"tx_fcoe_segmentation": "off [requested on]",
"tx_gre_csum_segmentation": "off [requested on]",
"tx_gre_segmentation": "off [requested on]",
"tx_gso_partial": "off [fixed]",
"tx_gso_robust": "off [fixed]",
"tx_ipxip4_segmentation": "off [requested on]",
"tx_ipxip6_segmentation": "off [requested on]",
"tx_lockless": "on [fixed]",
"tx_nocache_copy": "off",
"tx_scatter_gather": "on",
"tx_scatter_gather_fraglist": "off [requested on]",
"tx_sctp_segmentation": "on",
"tx_tcp6_segmentation": "on",
"tx_tcp_ecn_segmentation": "on",
"tx_tcp_mangleid_segmentation": "on",
"tx_tcp_segmentation": "on",
"tx_udp_segmentation": "off [fixed]",
"tx_udp_tnl_csum_segmentation": "on",
"tx_udp_tnl_segmentation": "on",
"tx_vlan_offload": "off [fixed]",
"tx_vlan_stag_hw_insert": "off [fixed]",
"udp_fragmentation_offload": "off",
"vlan_challenged": "off [fixed]"
},
"hw_timestamp_filters": [
"none",
"all"
],
"ipv4": {
"address": "10.43.56.241",
"broadcast": "10.43.56.255",
"netmask": "255.255.255.224",
"network": "10.43.56.224"
},
Я хочу извлечь факты «сеть»: «10.43.56.224» Когда я пробую ansible_ens2f0.11.ipv4.network из -за точки между интерфейсом и выходом VLAN_ID. он думает, что его субэлемент, но это не так.
Подробнее здесь:
https://stackoverflow.com/questions/795 ... ce-vlan-id
1743653277
Anonymous
У меня есть этот образец Playbook, и он работает нормально.[code]- hosts: localhost gather_facts: true tasks: - name: Print network interface details debug: msg: "{{ ansible_ens2f0.ipv4.network }}/{{ ansible_ens2f0.ipv4.netmask }}" < /code> Если я попробую с тегом VLAN (11[/code]) [code]- hosts: localhost gather_facts: true tasks: - name: Print network interface details debug: msg: "{{ ansible_ens2f0.11.ipv4.network }}/{{ ansible_ens2f0.11.ipv4.netmask }}" < /code> Затем получение ошибки, короткими < /p> dict object has no element 11 < /code> и полное сообщение < /pbr /> TASK [Print network interface details] *************************************************************************************************************************************************************************************************************************************** fatal: [localhost]: FAILED! => {"msg": "The task includes an option with an undefined variable. The error was: dict object has no element 11\n\nThe error appears to have been in '/home/ubuntu/net.yml': line 4, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n tasks:\n - name: Print network interface details\n ^ here\n"} [/code] Как мне объединить vlan_id в переменной?[code]ansible localhost -m setup < /code> "ansible_ens2f0.11": { "active": true, "device": "ens2f0.11", "features": { "esp_hw_offload": "off [fixed]", "esp_tx_csum_hw_offload": "off [fixed]", "fcoe_mtu": "off [requested on]", "generic_receive_offload": "on", "generic_segmentation_offload": "on", "highdma": "on", "hw_tc_offload": "off [fixed]", "l2_fwd_offload": "off [fixed]", "large_receive_offload": "off [fixed]", "loopback": "off [fixed]", "netns_local": "off [fixed]", "ntuple_filters": "off [fixed]", "receive_hashing": "off [fixed]", "rx_all": "off [fixed]", "rx_checksumming": "off [fixed]", "rx_fcs": "off [fixed]", "rx_gro_hw": "off [fixed]", "rx_udp_tunnel_port_offload": "off [fixed]", "rx_vlan_filter": "off [fixed]", "rx_vlan_offload": "off [fixed]", "rx_vlan_stag_filter": "off [fixed]", "rx_vlan_stag_hw_parse": "off [fixed]", "scatter_gather": "on", "tcp_segmentation_offload": "on", "tls_hw_record": "off [fixed]", "tls_hw_rx_offload": "off [fixed]", "tls_hw_tx_offload": "off [fixed]", "tx_checksum_fcoe_crc": "off [requested on]", "tx_checksum_ip_generic": "on", "tx_checksum_ipv4": "off [fixed]", "tx_checksum_ipv6": "off [fixed]", "tx_checksum_sctp": "off [requested on]", "tx_checksumming": "on", "tx_esp_segmentation": "off [fixed]", "tx_fcoe_segmentation": "off [requested on]", "tx_gre_csum_segmentation": "off [requested on]", "tx_gre_segmentation": "off [requested on]", "tx_gso_partial": "off [fixed]", "tx_gso_robust": "off [fixed]", "tx_ipxip4_segmentation": "off [requested on]", "tx_ipxip6_segmentation": "off [requested on]", "tx_lockless": "on [fixed]", "tx_nocache_copy": "off", "tx_scatter_gather": "on", "tx_scatter_gather_fraglist": "off [requested on]", "tx_sctp_segmentation": "on", "tx_tcp6_segmentation": "on", "tx_tcp_ecn_segmentation": "on", "tx_tcp_mangleid_segmentation": "on", "tx_tcp_segmentation": "on", "tx_udp_segmentation": "off [fixed]", "tx_udp_tnl_csum_segmentation": "on", "tx_udp_tnl_segmentation": "on", "tx_vlan_offload": "off [fixed]", "tx_vlan_stag_hw_insert": "off [fixed]", "udp_fragmentation_offload": "off", "vlan_challenged": "off [fixed]" }, "hw_timestamp_filters": [ "none", "all" ], "ipv4": { "address": "10.43.56.241", "broadcast": "10.43.56.255", "netmask": "255.255.255.224", "network": "10.43.56.224" }, [/code] Я хочу извлечь факты «сеть»: «10.43.56.224» Когда я пробую ansible_ens2f0.11.ipv4.network из -за точки между интерфейсом и выходом VLAN_ID. он думает, что его субэлемент, но это не так. Подробнее здесь: [url]https://stackoverflow.com/questions/79549149/how-to-extract-facts-with-dot-in-variable-name-interface-vlan-id[/url]