msg The task includes an option with an undefined variable.
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 }}"
- udev
-
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?
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.