- name: Get physical interfaces names
command: find /sys/class/net -type l -not -lname '*virtual*' -printf '%f\n'
register: phyintcmd
changed_when: false
check_mode: false
- name: Show interfaces details
debug:
msg: "{{ lookup('vars', 'macaddress' + item) }}"
loop: "{{ phyintcmd.stdout_lines }}"
а как мне теперь имя интерфейчас и мак вытащить и вписать в lineinfile ?
вывод
TASK [Show interfaces details] *******************************************************************************************************************************************************************
ok: [5.39.219.123] => (item=enp7s0) => {
"msg": {
"active": true,
"device": "enp7s0",
"features": {
"busy_poll": "off [fixed]",
"fcoe_mtu": "off [fixed]",
"generic_receive_offload": "on",
"generic_segmentation_offload": "on",
"highdma": "on [fixed]",
"hw_tc_offload": "on",
"l2_fwd_offload": "off [fixed]",
"large_receive_offload": "off [fixed]",
"loopback": "off [fixed]",
"netns_local": "off [fixed]",
"ntuple_filters": "off",
"receive_hashing": "on",
"rx_all": "off",
"rx_checksumming": "on",
"rx_fcs": "off [fixed]",
"rx_gro_hw": "off [fixed]",
"rx_udp_tunnel_port_offload": "off [fixed]",
"rx_vlan_filter": "on [fixed]",
"rx_vlan_offload": "on",
"rx_vlan_stag_filter": "off [fixed]",
"rx_vlan_stag_hw_parse": "off [fixed]",
"scatter_gather": "on",
"tcp_segmentation_offload": "on",
"tx_checksum_fcoe_crc": "off [fixed]",
"tx_checksum_ip_generic": "on",
"tx_checksum_ipv4": "off [fixed]",
"tx_checksum_ipv6": "off [fixed]",
"tx_checksum_sctp": "on",
"tx_checksumming": "on",
"tx_fcoe_segmentation": "off [fixed]",
"tx_gre_csum_segmentation": "on",
"tx_gre_segmentation": "on",
"tx_gso_partial": "on",
"tx_gso_robust": "off [fixed]",
"tx_ipip_segmentation": "on",
"tx_lockless": "off [fixed]",
"tx_nocache_copy": "off",
"tx_scatter_gather": "on",
"tx_scatter_gather_fraglist": "off [fixed]",
"tx_sctp_segmentation": "off [fixed]",
"tx_sit_segmentation": "on",
"tx_tcp6_segmentation": "on",
"tx_tcp_ecn_segmentation": "off [fixed]",
"tx_tcp_mangleid_segmentation": "off",
"tx_tcp_segmentation": "on",
"tx_udp_tnl_csum_segmentation": "on",
"tx_udp_tnl_segmentation": "on",
"tx_vlan_offload": "on",
"tx_vlan_stag_hw_insert": "off [fixed]",
"udp_fragmentation_offload": "off [fixed]",
"vlan_challenged": "off [fixed]"
},
"hw_timestamp_filters": [
"none",
"all"
],
"macaddress": "18:31:bf:d0:69:b5",
"module": "igb",
"mtu": 1500,
"pciid": "0000:07:00.0",
"phc_index": 0,
"promisc": true,
"speed": 1000,
"timestamping": [
"tx_hardware",
"tx_software",
"rx_hardware",
"rx_software",
"software",
"raw_hardware"
],
"type": "ether"
}
}
а из стандартных фактов без дополнительной таски никак?а потом https://www.middlewareinventory.com/blog/ansible-facts-list-how-to-use-ansible-facts/
а как отфильтровать виртульные инфейсы ?
а какие у виртуальных интерфейсов есть признаки?
да с этим подумаю , то для начала надо выводить мак и имя интерйсы и потом уже из всталять в строку
ну. так все это вроде есть в фактах
Data type of 'ansible_all_ipv4_addresses' is {{ ansible_interfaces }} могу просто греануть по eth* ?
Вы это имеете ввиду? ansible localhost -m setup -a 'filter=ansible_virbr[0-9]' localhost | SUCCESS => { "ansible_facts": { "ansible_virbr0": { "active": false, "device": "virbr0", "id": "8000.525400d09714", "interfaces": [ "virbr0-nic" ], "ipv4": { "address": "192.168.122.1", "broadcast": "192.168.122.255", "netmask": "255.255.255.0", "network": "192.168.122.0" }, "macaddress": "52:54:00:d0:97:14", "mtu": 1500, "promisc": false, "speed": -1, "stp": true, "type": "bridge" } }, "changed": false }
да , только как вытащить связку интерфейс и мак
имел ввиду наоборот физические интерфейсы оставить
У меня один, поэтому и выдал один. Запросите со своего сервера где связка интерфейсов, полную выдачу, посмотрите что вам нужно отфильтровать и напишите нужные фильтры (-a 'filter=') Мак, кстати, в выдаче есть.
ansible localhost -m setup -a 'filter=ansible_eth[0-9]' localhost | SUCCESS => { "ansible_facts": { "ansible_eth0": { "active": false, "device": "eth0", "macaddress": "24:b6:fd:11:49:49", "module": "r8169", "mtu": 1500, "pciid": "0000:02:00.0", "promisc": false, "speed": -1, "type": "ether" } }, "changed": false }
а как это вызвать в плейбуке ?
--- - name: Ansible Variable Example Playbook hosts: all tasks: # display the variable data type - debug: msg: - " Data type of 'ansible_all_ipv4_addresses' is {{ ansible_interfaces }} " - " Data type of 'ansible_all_ipv4_addresses' is {{ ansible_enp7s0 }} " # Simply printing the value of fact which is Ansible UnSafe Text type # - debug: # msg: "{{ansible_default_ipv4.macaddress}}" # Accessing the Second Element of the list - debug: msg: "{{ansible_interfaces[1].macaddress}}" - debug: msg: "{{ansible_enp7s0.macaddress}}" - debug: msg: "{{ansible_enp8s0.macaddress}}"
Обсуждают сегодня