-1

i´m trying to rename ethernet-interfaces on Linux. Each interface with the name enp0s* have to be eth*. First, i create udev-rules for renaming. that works fine. Secondly i have to create new configuration-files for each interface ( ' etc/sysconfig/network-scripts/ifcfg-eth* ' ). I don´t know, how to create the loop to place parameters in each interface. Can somneone help me?

Thats an extract of my playbook:

- name: Get new interface-names of the new created udev-rules
  become: yes
  shell: cat /etc/udev/rules.d/70-persisten-ipoib.rules.cfg | egrep -i 'eth.'
  register: car

- name: Create new-ifcfg-eth* files
  template:
  with_items: "{{ car.stdout_lines }}"
  register: cat
  template: src= roles/configure_network/templates/create_ifcfg.cfg.j2    dest=/etc/sysconfig/network-scripts/ifcfg-{{ item }}

# Template: roles/configure_network/templates/create_ifcfg.cfg.j2

{% for interface in cat.results %}
NAME="eth{{ item.name }}
TYPE=Ethernet
BOOTPROTO={{item.bootproto|default('dhcp')}}
IPV4_FAILURE_FATAL=no
IPV6INIT=no
{% if item.ipaddress is defined %}
IPADDR={{item.ipaddress}}
{% endif %}
{% if item.netmask is defined %}
NETMASK={{item.netmask}}
{% endif %}
{% if item.gateway is defined %}
GATEWAY={{item.gateway}}
{% endif %}
PEERDNS=no
{% if item.dns is defined %}
DNS1={{item.dns}}
{% endif %}
ONBOOT={{item.onboot|default('yes')}}
{% endfor %}
mwester
  • 1
  • 1
  • This isn't answering your question, but there are other ways of achieving what you want - see *I don't like this, how do I disable this?* [here](https://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames/). – mjturner Dec 08 '17 at 13:42

1 Answers1

0

Just fix your syntax:

- name: Create new-ifcfg-eth* files
  template:
    src: create_ifcfg.cfg.j2
    dest: /etc/sysconfig/network-scripts/ifcfg-{{ item }}
  with_items: "{{ car.stdout_lines }}"
  register: cat

Remove double template call, use relative path (no need to define full path to role's own templates), use YAML syntax instead of key=value (you had spaces in them, which are not allowed).

Konstantin Suvorov
  • 65,183
  • 9
  • 162
  • 193