Inital release 0.1.0
This commit is contained in:
		
							
								
								
									
										9
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										9
									
								
								CHANGELOG.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,9 @@
 | 
			
		||||
# Changelog
 | 
			
		||||
All notable changes to this project will be documented in this file.
 | 
			
		||||
 | 
			
		||||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
 | 
			
		||||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 | 
			
		||||
 | 
			
		||||
## [0.1.0] - 2020-06-04
 | 
			
		||||
### Added
 | 
			
		||||
- Inital release
 | 
			
		||||
							
								
								
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								LICENSE
									
									
									
									
									
								
							@@ -1,6 +1,6 @@
 | 
			
		||||
MIT License
 | 
			
		||||
 | 
			
		||||
Copyright (c) 2020 Zmey!
 | 
			
		||||
Copyright (c) 2020 Oleg "Zmey!" Vasiliev
 | 
			
		||||
 | 
			
		||||
Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
			
		||||
of this software and associated documentation files (the "Software"), to deal
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										74
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										74
									
								
								README.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,74 @@
 | 
			
		||||
networkd 
 | 
			
		||||
=========
 | 
			
		||||
 | 
			
		||||
An Ansible role for configuring systemd-networkd.
 | 
			
		||||
 | 
			
		||||
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
 | 
			
		||||
 | 
			
		||||
Requirements
 | 
			
		||||
------------
 | 
			
		||||
 | 
			
		||||
This role assumes that networkd is already present in the system. So it should be suitable for any distro with networkd.
 | 
			
		||||
 | 
			
		||||
Role Variables
 | 
			
		||||
--------------
 | 
			
		||||
 | 
			
		||||
Example configuration. Follow networkd documentation to construct yours.
 | 
			
		||||
```yaml
 | 
			
		||||
networkd:
 | 
			
		||||
 link:
 | 
			
		||||
     # This is file name
 | 
			
		||||
   - name: eth0
 | 
			
		||||
     # This is prefix for file. This results in following file name: 50-eth0.link
 | 
			
		||||
     priority: 50
 | 
			
		||||
     content:
 | 
			
		||||
       - Match:
 | 
			
		||||
         - MACAddress: "aa:bb:cc:dd:ee:ff"
 | 
			
		||||
       - Link:
 | 
			
		||||
         - Name: eth0
 | 
			
		||||
 netdev:
 | 
			
		||||
   - name: br0
 | 
			
		||||
     priority: 50
 | 
			
		||||
     content:
 | 
			
		||||
       - NetDev:
 | 
			
		||||
         - Name: br0
 | 
			
		||||
         - Kind: bridge
 | 
			
		||||
 network:
 | 
			
		||||
   - name: eth0
 | 
			
		||||
     priority: 50
 | 
			
		||||
     content:
 | 
			
		||||
       - Match:
 | 
			
		||||
         - Name: eth0
 | 
			
		||||
       - Network:
 | 
			
		||||
         - DHCP: ipv4
 | 
			
		||||
         - LinkLocalAddressing: no
 | 
			
		||||
         - LLDP: yes
 | 
			
		||||
       - DHCPv4:
 | 
			
		||||
         - UseHostname: no
 | 
			
		||||
         - Hostname: gimme-some-addr
 | 
			
		||||
         - UseMTU: yes
 | 
			
		||||
   - name: br0_slaves
 | 
			
		||||
     priority: 50
 | 
			
		||||
     content:
 | 
			
		||||
       - Match:
 | 
			
		||||
         - MACAddress: "11:bb:cc:dd:ee:ff 22:bb:cc:dd:ee:ff"
 | 
			
		||||
       - Network:
 | 
			
		||||
         - Bridge: br0
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
What to do on configuration changes. Could be "restart", "reload" or "nothing". Variable is mandatory.
 | 
			
		||||
```yaml
 | 
			
		||||
networkd_apply_action: "restart"
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
Custom content for `/etc/resolv.conf`. Every element in list is string in file. Variable is optional.
 | 
			
		||||
```yaml
 | 
			
		||||
networkd_resolv_conf_content:
 | 
			
		||||
  - nameserver 1.1.1.1
 | 
			
		||||
  - nameserver 8.8.8.8
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
License
 | 
			
		||||
-------
 | 
			
		||||
 | 
			
		||||
MIT
 | 
			
		||||
							
								
								
									
										6
									
								
								defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								defaults/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,6 @@
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
networkd:
 | 
			
		||||
 | 
			
		||||
# Could be "restart", "reload" or "nothing"
 | 
			
		||||
networkd_apply_action: "restart"
 | 
			
		||||
@@ -1,6 +1,17 @@
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
- name: networkd | Reload configuration
 | 
			
		||||
- name: networkd | Do restart
 | 
			
		||||
  systemd:
 | 
			
		||||
    name: systemd-networkd
 | 
			
		||||
    state: restarted
 | 
			
		||||
 | 
			
		||||
# From man:
 | 
			
		||||
# Reload .netdev and .network files. If a new .netdev file is found, then the corresponding netdev is created.
 | 
			
		||||
# Note that even if an existing .netdev is modified or removed, systemd-networkd does not update or remove the netdev.
 | 
			
		||||
# If a new, modified or removed .network file is found, then all interfaces which match the file are reconfigured.
 | 
			
		||||
- name: networkd | Do reload
 | 
			
		||||
  shell: networkctl reload
 | 
			
		||||
 | 
			
		||||
- name: networkd | Do nothing
 | 
			
		||||
  debug:
 | 
			
		||||
    msg: "Not applying new configuration due to selected action."
 | 
			
		||||
							
								
								
									
										15
									
								
								meta/main.yml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								meta/main.yml
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,15 @@
 | 
			
		||||
galaxy_info:
 | 
			
		||||
  author: 'Oleg "Zmey!" Vasiliev'
 | 
			
		||||
  description: An Ansible role for configuring systemd-networkd
 | 
			
		||||
 | 
			
		||||
  license: MIT
 | 
			
		||||
 | 
			
		||||
  min_ansible_version: 2.4
 | 
			
		||||
 | 
			
		||||
  galaxy_tags:
 | 
			
		||||
    - networking
 | 
			
		||||
    - networkd
 | 
			
		||||
    - systemd
 | 
			
		||||
 | 
			
		||||
dependencies: []
 | 
			
		||||
  
 | 
			
		||||
@@ -9,7 +9,7 @@
 | 
			
		||||
    group: root
 | 
			
		||||
  with_items: "{{ networkd.link | default([]) }}"
 | 
			
		||||
  register: networkd_deployed_link
 | 
			
		||||
  notify: networkd | Reload configuration
 | 
			
		||||
  notify: networkd | Do {{ networkd_apply_action }}
 | 
			
		||||
 | 
			
		||||
- name: networkd | Deploy .netdev configs
 | 
			
		||||
  template:
 | 
			
		||||
@@ -20,7 +20,7 @@
 | 
			
		||||
    group: root
 | 
			
		||||
  with_items: "{{ networkd.netdev | default([]) }}"
 | 
			
		||||
  register: networkd_deployed_netdev
 | 
			
		||||
  notify: networkd | Reload configuration
 | 
			
		||||
  notify: networkd | Do {{ networkd_apply_action }}
 | 
			
		||||
 | 
			
		||||
- name: networkd | Deploy .network configs
 | 
			
		||||
  template:
 | 
			
		||||
@@ -31,4 +31,4 @@
 | 
			
		||||
    group: root
 | 
			
		||||
  with_items: "{{ networkd.network | default([]) }}"
 | 
			
		||||
  register: networkd_deployed_network
 | 
			
		||||
  notify: networkd | Reload configuration
 | 
			
		||||
  notify: networkd | Do {{ networkd_apply_action }}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,12 @@
 | 
			
		||||
---
 | 
			
		||||
 | 
			
		||||
- name: Check role vars
 | 
			
		||||
  assert:
 | 
			
		||||
    that:
 | 
			
		||||
      - networkd_apply_action == "restart" or networkd_apply_action == "reload" or networkd_apply_action == "nothing"
 | 
			
		||||
    fail_msg: 'networkd_apply_action shoud be "restart", "reload" or "nothing"'
 | 
			
		||||
    quiet: yes
 | 
			
		||||
 | 
			
		||||
- import_tasks: deploy_configs.yml
 | 
			
		||||
 | 
			
		||||
- import_tasks: remove_unmanaged.yml
 | 
			
		||||
@@ -11,6 +18,7 @@
 | 
			
		||||
    mode: 644
 | 
			
		||||
    owner: root
 | 
			
		||||
    group: root
 | 
			
		||||
  when: networkd_resolv_conf_content is defined
 | 
			
		||||
 | 
			
		||||
- name: networkd | Enable and start service
 | 
			
		||||
  systemd:
 | 
			
		||||
 
 | 
			
		||||
@@ -17,4 +17,4 @@
 | 
			
		||||
    - (item.path) not in ( networkd_deployed_link | json_query('results[].invocation.module_args.dest') | default([]) )
 | 
			
		||||
    - (item.path) not in ( networkd_deployed_netdev | json_query('results[].invocation.module_args.dest') | default([]) )
 | 
			
		||||
    - (item.path) not in ( networkd_deployed_network | json_query('results[].invocation.module_args.dest') | default([]) )
 | 
			
		||||
  notify: networkd | Reload configuration
 | 
			
		||||
  notify: networkd | Do {{ networkd_apply_action }}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,4 +1,4 @@
 | 
			
		||||
# {{ ansible_managed }}
 | 
			
		||||
{% for item in networkd_resolver %}
 | 
			
		||||
{% for item in networkd_resolv_conf_content %}
 | 
			
		||||
{{ item }}
 | 
			
		||||
{% endfor %}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user