72 lines
2.3 KiB
YAML
72 lines
2.3 KiB
YAML
---
|
|
- name: (rhel) Check if ifcfg file exists for interface
|
|
ansible.builtin.stat:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
register: _rhel_ifcfg_file
|
|
|
|
- name: (rhel) Create ifcfg file with static configuration
|
|
ansible.builtin.copy:
|
|
dest: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
content: |
|
|
TYPE=Ethernet
|
|
BOOTPROTO=static
|
|
NAME={{ INTERFACE_NAME }}
|
|
DEVICE={{ INTERFACE_NAME }}
|
|
ONBOOT=yes
|
|
IPADDR={{ STATIC_IP | regex_replace('/.*', '') }}
|
|
PREFIX={{ STATIC_IP | regex_replace('.*/', '') }}
|
|
GATEWAY={{ STATIC_GATEWAY }}
|
|
DNS1={{ STATIC_DNS1 }}
|
|
DNS2={{ STATIC_DNS2 }}
|
|
mode: "0644"
|
|
when: not _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Ensure BOOTPROTO is set to static
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^BOOTPROTO="
|
|
line: "BOOTPROTO=static"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Ensure ONBOOT is set to yes
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^ONBOOT="
|
|
line: "ONBOOT=yes"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Set IPADDR
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^IPADDR="
|
|
line: "IPADDR={{ STATIC_IP | regex_replace('/.*', '') }}"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Set PREFIX
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^PREFIX="
|
|
line: "PREFIX={{ STATIC_IP | regex_replace('.*/', '') }}"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Set GATEWAY
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^GATEWAY="
|
|
line: "GATEWAY={{ STATIC_GATEWAY }}"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Set DNS1
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^DNS1="
|
|
line: "DNS1={{ STATIC_DNS1 }}"
|
|
when: _rhel_ifcfg_file.stat.exists
|
|
|
|
- name: (rhel) Set DNS2
|
|
ansible.builtin.lineinfile:
|
|
path: "/etc/sysconfig/network-scripts/ifcfg-{{ INTERFACE_NAME }}"
|
|
regexp: "^DNS2="
|
|
line: "DNS2={{ STATIC_DNS2 }}"
|
|
when: _rhel_ifcfg_file.stat.exists
|