msg The task includes an option with an undefined variable.

Latest response

Hi Everyone !

I'm missing something on this playbook based on RedHat article to replace ethx to emx interface...

The error was: 'dict object' has no attribute 'macaddress'

-name: Update udev rules


  • name: Rename network interfaces
    hosts: all
    become: true
    vars:
    src_prefix: "eth"
    dst_prefix: "ens"
    osnet_conf: "/etc/os-net-config/config.json"
    src_interfaces: "{{ ansible_interfaces | select('match', src_prefix ~ '.*') | sort | list }}"
    undercloud_conf: "~/undercloud.conf"
    tasks:

    • debug:
      msg: "{{ src_interfaces }}"

    • name: Update udev rules
      tags:

      • udev
        lineinfile:
        line: >
        SUBSYSTEM=="net",
        ACTION=="add",
        DRIVERS=="?",
        ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",
        NAME="{{ item | replace(src_prefix, dst_prefix) }}"
        path: /etc/udev/rules.d/70-rhosp-persistent-net.rules
        create: true
        with_items: "{{ src_interfaces | reject('match', '^.
        \..*$') | list }}"

Attachments

Responses

Do you find anything related to the MAC-address in the Ansible facts?

- name: Debug ansible_facts
  debug:
    var: ansible_facts

Do you have a link to the article you're referring to?

Hi J Schmidt Yes I got it Type this output: }, "default_ipv4": { .... "macaddress": "00:50:56:b3:1c:1f", ....

This code seems to work for me:

- name: Rename network interfaces
  hosts: all
#  become: true
  vars:
    src_prefix: "eth"
    dst_prefix: "ens"
    src_interfaces: "{{ ansible_interfaces | select('match', src_prefix ~ '.*') | sort | list }}"
  tasks:
    - name: Debug network interfaces
      debug:
        msg: "{{ src_interfaces }}"

    - name: Update udev rules
      tags: udev
      lineinfile:
        regexp: >
          SUBSYSTEM=="net",
          ACTION=="add",
          DRIVERS=="\?",
          ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",
          NAME="{{ item | replace(src_prefix, dst_prefix) }}"
        line: >
          SUBSYSTEM=="net",
          ACTION=="add",
          DRIVERS=="?",
          ATTR{address}=="{{ ansible_facts[item]['perm_macaddress'] | default(ansible_facts[item]['macaddress']) }}",
          NAME="{{ item | replace(src_prefix, dst_prefix) }}"
        path: /tmp/70-rhosp-persistent-net.rules
        create: true
      with_items: '{{ src_interfaces | reject("match", "^.\..*$") | list }}'

I'm using regexp to make sure line is only added if the line doesn't exist already.
Disclaimer: Only tested on a RHEL 8 test-server of mine.
For testing, it writes to /tmp as shown.

Yeh ! Its partial function to me... O got some progress and got failed into one host and success for another... I need more nodes to make sure it was related to one specific host

Hi J Schmidt... Looks like in my case I have sub interfaces as eth0:1... that no have macaddress it is causing a look on the playbook to fatal error... looping eth0, eth0_1, eth1. the task failure indicates that ansible_facts['eth0']['macaddress'] exists, but ansible_facts['eth0_1']['macaddress'] does not

Any Idea to ignore interfaces without macadress ?

If you just want to ignore some interfaces, you could probably add more "rejects" in the last line:

with_items: '{{ src_interfaces | reject("match", "^.\..*$") | list }}'

Try adding a new reject after the existing one. You'll need a pipe-sign ("|") too.

I cab try it... This is my output... ok: [10.132.78.192] META: ran handlers

TASK [Debug message] *********************************************************** task path: /app/awxtmp/bwrap_2947532_b592cqna/awx_2947532_d0izo5ch/project/replace_nic_ethx.yml:12 ok: [10.132.78.192] => { "src_interfaces": [ "eth0", "eth0_1", "eth1" ] }

TASK [Debug ansible_facts] ***************************************************** task path: /app/awxtmp/bwrap_2947532_b592cqna/awx_2947532_d0izo5ch/project/replace_nic_ethx.yml:15 ok: [10.132.78.192] => { "ansible_facts['eth1']": { "active": true, "device": "eth1", "features": { "busy_poll": "off [fixed]", "fcoe_mtu": "off [fixed]", "generic_receive_offload": "on", "generic_segmentation_offload": "on", "highdma": "on", "hw_tc_offload": "off [fixed]", "l2_fwd_offload": "off [fixed]", "large_receive_offload": "on", "loopback": "off [fixed]", "netns_local": "off [fixed]", "ntuple_filters": "off [fixed]", "receive_hashing": "on", "rx_all": "off [fixed]", "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": "off [fixed]", "tx_checksumming": "on", "tx_fcoe_segmentation": "off [fixed]", "tx_gre_csum_segmentation": "off [fixed]", "tx_gre_segmentation": "off [fixed]", "tx_gso_partial": "off [fixed]", "tx_gso_robust": "off [fixed]", "tx_ipip_segmentation": "off [fixed]", "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": "off [fixed]", "tx_tcp6_segmentation": "on", "tx_tcp_ecn_segmentation": "off [fixed]", "tx_tcp_mangleid_segmentation": "off", "tx_tcp_segmentation": "on", "tx_udp_tnl_csum_segmentation": "off [fixed]", "tx_udp_tnl_segmentation": "off [fixed]", "tx_vlan_offload": "on", "tx_vlan_stag_hw_insert": "off [fixed]", "udp_fragmentation_offload": "off [fixed]", "vlan_challenged": "off [fixed]" }, "hw_timestamp_filters": [], "ipv4": { "address": "10.132.196.252", "broadcast": "10.132.197.255", "netmask": "255.255.254.0", "network": "10.132.196.0" }, "macaddress": "00:50:56:8d:05:97", "module": "vmxnet3", "mtu": 1500, "pciid": "0000:13:00.0", "promisc": false, "speed": 10000, "timestamping": [ "rx_software", "software" ], "type": "ether" } }

TASK [Update udev rules] ******************************************************* task path: /app/awxtmp/bwrap_2947532_b592cqna/awx_2947532_d0izo5ch/project/replace_nic_ethx.yml:23 Using module file /app/awxvenv/ansible-2.7/lib/python2.7/site-packages/ansible/modules/files/lineinfile.py <10.132.78.192> ESTABLISH SSH CONNECTION FOR USER: GXSONLINE\svc_qansible <10.132.78.192> SSH: EXEC sshpass -d9 ssh -C -o ControlMaster=auto -o ControlPersist=60s -o PreferredAuthentications=publickey,keyboard-interactive,password -o StrictHostKeyChecking=no -o 'IdentityFile="/var/lib/awx/.ssh/id_rsa"' -o 'User=GXSONLINE\svc_qansible' -o ConnectTimeout=150 -o ControlPath=/app/awxtmp/bwrap_2947532_b592cqna/awx_2947532_d0izo5ch/cp/abf56c74d6 10.132.78.192 '/bin/sh -c '"'"'sudo -H -S -p "[sudo via ansible, key=cgekqzkefmrasrysxjqxpqdgeidqtafa] password: " -u root /bin/sh -c '"'"'"'"'"'"'"'"'echo BECOME-SUCCESS-cgekqzkefmrasrysxjqxpqdgeidqtafa; /usr/bin/python'"'"'"'"'"'"'"'"' && sleep 0'"'"'' Escalation succeeded <10.132.78.192> (0, '\n{"msg": "line added", "diff": [{"after": "", "before_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)", "after_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)", "before": ""}, {"before_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)", "after_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)"}], "changed": true, "backup": "", "invocation": {"module_args": {"directory_mode": null, "force": null, "remote_src": null, "backrefs": false, "insertafter": null, "path": "/etc/udev/rules.d/70-rhosp-persistent-net.rules", "owner": null, "follow": false, "validate": null, "group": null, "insertbefore": null, "unsafe_writes": null, "create": true, "setype": null, "content": null, "serole": null, "state": "present", "selevel": null, "regexp": null, "line": "SUBSYSTEM==\\"net\\", ACTION==\\"add\\", DRIVERS==\\"?\\", ATTR{address}==\\"00:50:56:8d:fb:e3\\", NAME=\\"eno0\\"", "src": null, "seuser": null, "delimiter": null, "mode": null, "firstmatch": false, "attributes": null, "backup": false}}}\n', '') changed: [10.132.78.192] => (item=eth0) => { "backup": "", "changed": true, "diff": [ { "after": "", "after_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)", "before": "", "before_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (content)" }, { "after_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)", "before_header": "/etc/udev/rules.d/70-rhosp-persistent-net.rules (file attributes)" } ], "invocation": { "module_args": { "attributes": null, "backrefs": false, "backup": false, "content": null, "create": true, "delimiter": null, "directory_mode": null, "firstmatch": false, "follow": false, "force": null, "group": null, "insertafter": null, "insertbefore": null, "line": "SUBSYSTEM==\"net\", ACTION==\"add\", DRIVERS==\"?\", ATTR{address}==\"00:50:56:8d:fb:e3\", NAME=\"eno0\"", "mode": null, "owner": null, "path": "/etc/udev/rules.d/70-rhosp-persistent-net.rules", "regexp": null, "remote_src": null, "selevel": null, "serole": null, "setype": null, "seuser": null, "src": null, "state": "present", "unsafe_writes": null, "validate": null } }, "item": "eth0", "msg": "line added" } fatal: [10.132.78.192]: FAILED! => { "msg": "The task includes an option with an undefined variable. The error was: 'dict object' has no attribute 'macaddress'\n\nThe error appears to have been in '/app/awxtmp/bwrap_2947532_b592cqna/awx_2947532_d0izo5ch/project/replace_nic_ethx.yml': line 23, column 7, but may\nbe elsewhere in the file depending on the exact syntax problem.\n\nThe offending line appears to be:\n\n\n - name: Update udev rules\n ^ here\n" }

PLAY RECAP ********************************************************************* 10.132.78.192 : ok=3 changed=0 unreachable=0 failed=1