chore: first commit
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
# net-config
|
||||
|
||||
This role configures a network interface.
|
||||
|
||||
## Requirements
|
||||
|
||||
None
|
||||
|
||||
## Example Playbook
|
||||
|
||||
```yaml
|
||||
- hosts: servers
|
||||
roles:
|
||||
- role: net-config
|
||||
interface:
|
||||
name: lan0
|
||||
mac_address: 02:a0:c9:8d:7e:b6
|
||||
address: 192.168.1.2/24
|
||||
gateway: 192.168.1.254
|
||||
nameservers:
|
||||
- 1.1.1.1
|
||||
- 8.8.8.8
|
||||
```
|
||||
|
||||
## License
|
||||
|
||||
MIT
|
||||
|
||||
## Author Information
|
||||
|
||||
Jokester <main@jokester.fr>
|
||||
@@ -0,0 +1,19 @@
|
||||
---
|
||||
galaxy_info:
|
||||
author: Jokester <main@jokester.fr>
|
||||
description: Configure the network as set in the inventory
|
||||
license: MIT
|
||||
min_ansible_version: "2.10"
|
||||
galaxy_tags:
|
||||
- network
|
||||
- configuration
|
||||
- linux
|
||||
- debian
|
||||
- archlinux
|
||||
platforms:
|
||||
- name: Debian
|
||||
versions:
|
||||
- all
|
||||
- name: ArchLinux
|
||||
versions:
|
||||
- all
|
||||
@@ -0,0 +1,36 @@
|
||||
---
|
||||
- name: Check if the interface ipv4 address is defined
|
||||
block:
|
||||
- debug:
|
||||
msg: "Warning: iface {{ interface.name }} has no defined ipv4 address, skipping configuration"
|
||||
- name: Skip net-config role for {{ interface.name }}
|
||||
meta: end_play
|
||||
when: interface.ipv4.address is not defined
|
||||
|
||||
- name: Check if the interface is already configured
|
||||
stat:
|
||||
path: /etc/systemd/network/20-{{ interface.name }}.network
|
||||
register: network_file
|
||||
|
||||
- name: What patch is needed
|
||||
debug:
|
||||
msg: >-
|
||||
{%- if network_file.stat.exists == true -%}
|
||||
iface {{ interface.name }} is already configured, no action needed.
|
||||
{%- else -%}
|
||||
iface {{ interface.name }} will be configured.
|
||||
{%- endif -%}
|
||||
|
||||
- name: Create systemd-network link file
|
||||
when: network_file.stat.exists != true
|
||||
template:
|
||||
src: systemd.network.j2
|
||||
dest: /etc/systemd/network/20-{{ interface.name }}.network
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0644"
|
||||
|
||||
- name: Notify a reload is required
|
||||
set_fact:
|
||||
network_reload_required: true
|
||||
when: network_file.stat.exists != true
|
||||
@@ -0,0 +1,9 @@
|
||||
# This file describes the network interfaces available on your system
|
||||
# and how to activate them. For more information, see interfaces(5).
|
||||
|
||||
# The primary network interface
|
||||
allow-hotplug {{ interface.name }}
|
||||
iface {{ interface.name }} inet dhcp
|
||||
|
||||
# This is an autoconfigured IPv6 interface
|
||||
iface {{ interface.name }} inet6 auto
|
||||
@@ -0,0 +1,9 @@
|
||||
[Match]
|
||||
Name={{ interface.name }}
|
||||
|
||||
[Network]
|
||||
Address={{ interface.ipv4.address }}
|
||||
Gateway={{ interface.ipv4.gateway }}
|
||||
{% for dns in interface.ipv4.nameservers %}
|
||||
DNS={{ dns }}
|
||||
{% endfor %}
|
||||
Reference in New Issue
Block a user