Anonymous
Wie extrahiere ich Fakten mit Punkt im variablen Namen ('interface.vlan_id')?
Post
by Anonymous » 02 Apr 2025, 16:37
Ich habe dieses Beispiel-Spielbuch und es funktioniert gut.
Code: Select all
- hosts: localhost
gather_facts: true
tasks:
- name: Print network interface details
debug:
msg: "{{ ansible_ens2f0.ipv4.network }}/{{ ansible_ens2f0.ipv4.netmask }}"
< /code>
Wenn ich es mit VLAN -Tag versuche (11
)
Code: Select all
- hosts: localhost
gather_facts: true
tasks:
- name: Print network interface details
debug:
msg: "{{ ansible_ens2f0.11.ipv4.network }}/{{ ansible_ens2f0.11.ipv4.netmask }}"
< /code>
Dann erhalten Sie Fehler, kurz < /p>
dict object has no element 11
< /code>
und vollständige Nachricht < /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"}
Wie kann ich vlan_id in variabler?
Code: Select all
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"
},
Ich möchte Fakten "Netzwerk" extrahieren: "10.43.56.224" Wenn ich Ansilible_ens2f0.ipv4.network versuche, wegen des Punktes zwischen Schnittstelle und VLAN_ID, das eine Ausgabe verursacht. es denkt, sein Subelement, aber es ist nicht.
1743604627
Anonymous
Ich habe dieses Beispiel-Spielbuch und es funktioniert gut.[code]- hosts: localhost gather_facts: true tasks: - name: Print network interface details debug: msg: "{{ ansible_ens2f0.ipv4.network }}/{{ ansible_ens2f0.ipv4.netmask }}" < /code> Wenn ich es mit VLAN -Tag versuche (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> Dann erhalten Sie Fehler, kurz < /p> dict object has no element 11 < /code> und vollständige Nachricht < /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] Wie kann ich vlan_id in variabler?[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] Ich möchte Fakten "Netzwerk" extrahieren: "10.43.56.224" Wenn ich Ansilible_ens2f0.ipv4.network versuche, wegen des Punktes zwischen Schnittstelle und VLAN_ID, das eine Ausgabe verursacht. es denkt, sein Subelement, aber es ist nicht.