2017-12-08 2 views
-1

리눅스에서 이더넷 인터페이스의 이름을 바꾸려고합니다. enp0s *라는 이름의 각 인터페이스는 eth * 여야합니다. 첫째, 이름 바꾸기를위한 udev-rules를 만듭니다. 그건 잘 작동합니다. 둘째로 각 인터페이스 ('/ etc/sysconfig/network-scripts/ifcfg-eth *')에 대해 새로운 구성 파일을 만들어야합니다. 각 인터페이스에 매개 변수를 배치하는 루프를 만드는 방법을 모르겠습니다. somneone 나를 도울 수 있습니까?동적 파일을 만드는 방법은 무엇입니까?

- 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 %} 
+0

이것은 귀하의 질문에 대답하지 않지만 원하는 것을 성취 할 수있는 다른 방법이 있습니다. * 이것을 좋아하지 않습니다. 어떻게 비활성화합니까? * [여기] (https : //www.freedesktop. org/wiki/Software/systemd/PredictableNetworkInterfaceNames /)를 참조하십시오. – mjturner

답변

0

는 그냥 구문을 수정 :

- 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 

더블 template 호출을 제거, 사용 상대 경로 (필요

내 플레이 북의 추출물 그게 전부 역할 자신의 템플릿에 대한 전체 경로 정의)대신 YAML 구문 사용(공백이있어 허용되지 않습니다).

관련 문제