| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- ---
- - name: Rename network interfaces
- hosts: exampletarget
- become: true
- vars:
- src_prefix: "eth"
- dst_prefix: "em"
- 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 }}"
- - name: Rename ifcfg files
- tags:
- - ifcfg
- block:
- - name: Check that src_prefix files exists
- stat:
- path: /etc/sysconfig/network-scripts/ifcfg-{{ item }}
- register: nic_result
- with_items: "{{ src_interfaces }}"
- - name: Copy ifcfg files using dst_prefix
- copy:
- remote_src: true
- src: "{{ item.stat.path }}"
- dest: "{{ item.stat.path | replace(src_prefix, dst_prefix) }}"
- with_items: "{{ nic_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Edit NAME in new network-script files
- lineinfile:
- regexp: "^NAME=.*"
- line: "NAME={{ item.item | replace(src_prefix, dst_prefix) }}"
- path: "{{ item.stat.path | replace(src_prefix, dst_prefix) }}"
- with_items: "{{ nic_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Edit DEVICE in new network-script files
- lineinfile:
- regexp: "^DEVICE=.*"
- line: "DEVICE={{ item.item | replace(src_prefix, dst_prefix) }}"
- path: "{{ item.stat.path | replace(src_prefix, dst_prefix) }}"
- with_items: "{{ nic_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Backup old ifcfg network-script files
- copy:
- remote_src: true
- src: "{{ item.stat.path }}"
- dest: "{{ item.stat.path }}.bak"
- with_items: "{{ nic_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Remove old ifcfg network-script files
- file:
- path: "{{ item.stat.path }}"
- state: absent
- with_items: "{{ nic_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Rename route files
- tags:
- - routes
- block:
- - name: Check that route files exists
- stat:
- path: /etc/sysconfig/network-scripts/route-{{ item }}
- register: route_result
- with_items: "{{ src_interfaces }}"
- - name: Copy route files using dst_prefix
- copy:
- remote_src: true
- src: "{{ item.stat.path }}"
- dest: "{{ item.stat.path | replace(src_prefix, dst_prefix) }}"
- with_items: "{{ route_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Update dst_prefix in route files that use IP command arguments format
- replace:
- regexp: "{{ src_prefix }}"
- replace: "{{ dst_prefix }}"
- path: "{{ item.stat.path | replace(src_prefix, dst_prefix) }}"
- with_items: "{{ route_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Backup old route files
- copy:
- remote_src: true
- src: "{{ item.stat.path }}"
- dest: "{{ item.stat.path }}.bak"
- with_items: "{{ route_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Remove old route files
- file:
- path: "{{ item.stat.path }}"
- state: absent
- with_items: "{{ route_result.results }}"
- when: item.stat.exists
- loop_control:
- label: "{{ item.item }}"
- - name: Perform a final regex for any remaining src_prefix in ifcfg files
- tags:
- - ifcfg
- block:
- - name: Get a list of all ifcfg files
- find:
- paths: /etc/sysconfig/network-scripts/
- patterns: 'ifcfg-*'
- excludes: '*.bak'
- register: ifcfg_files
- - name: Perform final regex on ifcfg files
- replace:
- path: "{{ item[0].path }}"
- regexp: "{{ item[1] }}"
- replace: "{{ item[1] | replace(src_prefix, dst_prefix) }}"
- with_nested:
- - "{{ ifcfg_files.files }}"
- - "{{ src_interfaces }}"
- loop_control:
- label: "{{ item[1] }} -> {{ item[0].path }}"
- - name: Replace interface name in TripleO configuration files
- tags:
- - tripleo
- block:
- - name: Check if undercloud.conf exists
- stat:
- path: "{{ undercloud_conf }}"
- register: undercloud_conf_stat
- - name: Replace interface name in undercloud.conf
- replace:
- path: "{{ undercloud_conf }}"
- regexp: "{{ item }}"
- replace: "{{ item | replace(src_prefix, dst_prefix) }}"
- when: undercloud_conf_stat.stat.exists
- with_items: "{{ src_interfaces }}"
- - name: Check if os-net-config's config.json exists
- stat:
- path: "{{ osnet_conf }}"
- register: osnet_conf_stat
- - name: Replace interface name in config.json
- replace:
- path: "{{ osnet_conf }}"
- regexp: "{{ item }}"
- replace: "{{ item | replace(src_prefix, dst_prefix) }}"
- when: osnet_conf_stat.stat.exists
- with_items: "{{ src_interfaces }}"
|