我需要使用Ansible更改网络接口的名称。
例如 mv / etc / sysconfig / network-scripts / ifcfg-eno1675454 / etc / sysconfig / network-scripts / ifcfg-eth0
nmtui 并更改个人资料名称
我目前的操作方式-
- name: Copy interface file ifcfg-{{ ansible_default_ipv4.interface }} to ifcfg-etho
copy:
remote_src: True
src: '/etc/sysconfig/network-scripts/ifcfg-{{ ansible_default_ipv4.interface }}'
dest: /etc/sysconfig/network-scripts/ifcfg-eth0
- name: Replace device name to eth0 inside the file
replace:
path: '/etc/sysconfig/network-scripts/ifcfg-eth0'
regexp: "{{ ansible_default_ipv4.interface }}"
replace: "eth0"
要修改grub:
- name: update grub
lineinfile:
dest: "{{ grub_input_config }}"
regexp: "GRUB_CMDLINE_LINUX"
line: 'GRUB_CMDLINE_LINUX="crashkernel=auto rd.lvm.lv=centos/root rd.lvm.lv=centos/swap rhgb quiet net.ifnames=0 biosdevname=0" '
notify: "make grub config"
grub处理程序:
---
- name: make grub config
command: "{{ grub_mkconfig_cmd }} -o {{ grub_output_config }}"
默认值
grub_mkconfig_cmd: grub2-mkconfig
grub_output_config: /boot/grub2/grub.cfg
grub_input_config: /etc/default/grub
编辑:添加了代码
答案 0 :(得分:0)
当您运行此任务并重新启动系统时,更改是否保留? 在centos7中,我必须执行此额外的步骤才能使其永久存在:
GRUB_CMDLINE_LINUX="... net.ifnames=0 biosdevname=0 ..."
grub2-mkconfig -o /boot/grub2/grub.cfg