Real inital commit

master
Oleg "Zmey!" Vasiliev 2020-05-05 19:19:38 +03:00
parent 3e13c56880
commit 6a946541d5
6 changed files with 98 additions and 0 deletions

6
handlers/main.yml Normal file
View File

@ -0,0 +1,6 @@
---
- name: networkd | Reload configuration
systemd:
name: systemd-networkd
state: restarted

34
tasks/deploy_configs.yml Normal file
View File

@ -0,0 +1,34 @@
---
- name: networkd | Deploy .link configs
template:
src: networkd.j2
dest: "/etc/systemd/network/{{ item.priority }}-{{ item.name }}.link"
mode: 644
owner: root
group: root
with_items: "{{ networkd.link | default([]) }}"
register: networkd_deployed_link
notify: networkd | Reload configuration
- name: networkd | Deploy .netdev configs
template:
src: networkd.j2
dest: "/etc/systemd/network/{{ item.priority }}-{{ item.name }}.netdev"
mode: 644
owner: root
group: root
with_items: "{{ networkd.netdev | default([]) }}"
register: networkd_deployed_netdev
notify: networkd | Reload configuration
- name: networkd | Deploy .network configs
template:
src: networkd.j2
dest: "/etc/systemd/network/{{ item.priority }}-{{ item.name }}.network"
mode: 644
owner: root
group: root
with_items: "{{ networkd.network | default([]) }}"
register: networkd_deployed_network
notify: networkd | Reload configuration

22
tasks/main.yml Normal file
View File

@ -0,0 +1,22 @@
---
- import_tasks: deploy_configs.yml
- import_tasks: remove_unmanaged.yml
- name: networkd | Deploy resolv.conf
template:
src: resolv.conf.j2
dest: /etc/resolv.conf
mode: 644
owner: root
group: root
- name: networkd | Enable and start service
systemd:
name: systemd-networkd
state: started
enabled: yes
- name: networkd | Run handlers now
meta: flush_handlers

View File

@ -0,0 +1,20 @@
---
- name: networkd | Collect file list in network dir
find:
path: /etc/systemd/network
hidden: yes
register: networkd_found_files
check_mode: no
changed_when: false
- name: networkd | Remove unmanaged files
file:
path: "/etc/systemd/network/{{ item.path | basename }}"
state: absent
with_items:
- "{{ networkd_found_files.files }}"
when:
- (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

12
templates/networkd.j2 Normal file
View File

@ -0,0 +1,12 @@
# {{ ansible_managed }}
{% for section in item.content %}
{% for section_name, section_params in section.items() %}
[{{ section_name }}]
{% for item in section_params %}
{% for key, value in item.items() %}
{{ key }}={{ value }}
{% endfor %}
{% endfor %}
{% endfor %}
{% endfor %}

4
templates/resolv.conf.j2 Normal file
View File

@ -0,0 +1,4 @@
# {{ ansible_managed }}
{% for item in networkd_resolver %}
{{ item }}
{% endfor %}